
<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>pymatgen.electronic_structure.bandstructure &#8212; pymatgen 2020.7.3 documentation</title>
    <link rel="stylesheet" href="../../../_static/basic.css" type="text/css" />
    <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    <script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
    <script src="../../../_static/jquery.js"></script>
    <script src="../../../_static/underscore.js"></script>
    <script src="../../../_static/doctools.js"></script>
    <script src="../../../_static/language_data.js"></script>
    <script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" />
 
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-33990148-1']);
  _gaq.push(['_trackPageview']);
</script>

  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../pymatgen.html" accesskey="U">pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.electronic_structure.bandstructure</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
          <div class="body" role="main">
            
  <h1>Source code for pymatgen.electronic_structure.bandstructure</h1><div class="highlight"><pre>
<span></span><span class="c1"># coding: utf-8</span>
<span class="c1"># Copyright (c) Pymatgen Development Team.</span>
<span class="c1"># Distributed under the terms of the MIT License.</span>

<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">This module provides classes to define everything related to band structures.</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">re</span>
<span class="kn">import</span> <span class="nn">math</span>
<span class="kn">import</span> <span class="nn">itertools</span>
<span class="kn">import</span> <span class="nn">collections</span>
<span class="kn">import</span> <span class="nn">warnings</span>

<span class="kn">from</span> <span class="nn">monty.json</span> <span class="kn">import</span> <span class="n">MSONable</span>
<span class="kn">from</span> <span class="nn">pymatgen.core.periodic_table</span> <span class="kn">import</span> <span class="n">get_el_sp</span><span class="p">,</span> <span class="n">Element</span>
<span class="kn">from</span> <span class="nn">pymatgen.core.structure</span> <span class="kn">import</span> <span class="n">Structure</span>
<span class="kn">from</span> <span class="nn">pymatgen.core.lattice</span> <span class="kn">import</span> <span class="n">Lattice</span>
<span class="kn">from</span> <span class="nn">pymatgen.electronic_structure.core</span> <span class="kn">import</span> <span class="n">Spin</span><span class="p">,</span> <span class="n">Orbital</span>
<span class="kn">from</span> <span class="nn">pymatgen.symmetry.analyzer</span> <span class="kn">import</span> <span class="n">SpacegroupAnalyzer</span>
<span class="kn">from</span> <span class="nn">pymatgen.util.coord</span> <span class="kn">import</span> <span class="n">pbc_diff</span>

<span class="n">__author__</span> <span class="o">=</span> <span class="s2">&quot;Geoffroy Hautier, Shyue Ping Ong, Michael Kocher&quot;</span>
<span class="n">__copyright__</span> <span class="o">=</span> <span class="s2">&quot;Copyright 2012, The Materials Project&quot;</span>
<span class="n">__version__</span> <span class="o">=</span> <span class="s2">&quot;1.0&quot;</span>
<span class="n">__maintainer__</span> <span class="o">=</span> <span class="s2">&quot;Geoffroy Hautier&quot;</span>
<span class="n">__email__</span> <span class="o">=</span> <span class="s2">&quot;geoffroy@uclouvain.be&quot;</span>
<span class="n">__status__</span> <span class="o">=</span> <span class="s2">&quot;Development&quot;</span>
<span class="n">__date__</span> <span class="o">=</span> <span class="s2">&quot;March 14, 2012&quot;</span>


<div class="viewcode-block" id="Kpoint"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.bandstructure.html#pymatgen.electronic_structure.bandstructure.Kpoint">[docs]</a><span class="k">class</span> <span class="nc">Kpoint</span><span class="p">(</span><span class="n">MSONable</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Class to store kpoint objects. A kpoint is defined with a lattice and frac</span>
<span class="sd">    or cartesian coordinates syntax similar than the site object in</span>
<span class="sd">    pymatgen.core.structure.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">coords</span><span class="p">,</span> <span class="n">lattice</span><span class="p">,</span> <span class="n">to_unit_cell</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                 <span class="n">coords_are_cartesian</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            coords: coordinate of the kpoint as a numpy array</span>
<span class="sd">            lattice: A pymatgen.core.lattice.Lattice lattice object representing</span>
<span class="sd">                the reciprocal lattice of the kpoint</span>
<span class="sd">            to_unit_cell: Translates fractional coordinate to the basic unit</span>
<span class="sd">                cell, i.e., all fractional coordinates satisfy 0 &lt;= a &lt; 1.</span>
<span class="sd">                Defaults to False.</span>
<span class="sd">            coords_are_cartesian: Boolean indicating if the coordinates given are</span>
<span class="sd">                in cartesian or fractional coordinates (by default fractional)</span>
<span class="sd">            label: the label of the kpoint if any (None by default)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_lattice</span> <span class="o">=</span> <span class="n">lattice</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_fcoords</span> <span class="o">=</span> <span class="n">lattice</span><span class="o">.</span><span class="n">get_fractional_coords</span><span class="p">(</span><span class="n">coords</span><span class="p">)</span> \
            <span class="k">if</span> <span class="n">coords_are_cartesian</span> <span class="k">else</span> <span class="n">coords</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_label</span> <span class="o">=</span> <span class="n">label</span>

        <span class="k">if</span> <span class="n">to_unit_cell</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_fcoords</span><span class="p">)):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_fcoords</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">-=</span> <span class="n">math</span><span class="o">.</span><span class="n">floor</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_fcoords</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">_ccoords</span> <span class="o">=</span> <span class="n">lattice</span><span class="o">.</span><span class="n">get_cartesian_coords</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_fcoords</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">lattice</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        The lattice associated with the kpoint. It&#39;s a</span>
<span class="sd">        pymatgen.core.lattice.Lattice object</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_lattice</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">label</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        The label associated with the kpoint</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_label</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">frac_coords</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        The fractional coordinates of the kpoint as a numpy array</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_fcoords</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">cart_coords</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        The cartesian coordinates of the kpoint as a numpy array</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_ccoords</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">a</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Fractional a coordinate of the kpoint</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_fcoords</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">b</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Fractional b coordinate of the kpoint</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_fcoords</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">c</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Fractional c coordinate of the kpoint</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_fcoords</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>

    <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns a string with fractional, cartesian coordinates and label</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="s2">&quot;</span><span class="si">{}</span><span class="s2"> </span><span class="si">{}</span><span class="s2"> </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">frac_coords</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">cart_coords</span><span class="p">,</span>
                                 <span class="bp">self</span><span class="o">.</span><span class="n">label</span><span class="p">)</span>

<div class="viewcode-block" id="Kpoint.as_dict"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.bandstructure.html#pymatgen.electronic_structure.bandstructure.Kpoint.as_dict">[docs]</a>    <span class="k">def</span> <span class="nf">as_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Json-serializable dict representation of a kpoint</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="p">{</span><span class="s2">&quot;lattice&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">lattice</span><span class="o">.</span><span class="n">as_dict</span><span class="p">(),</span>
                <span class="s2">&quot;fcoords&quot;</span><span class="p">:</span> <span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">frac_coords</span><span class="p">),</span>
                <span class="s2">&quot;ccoords&quot;</span><span class="p">:</span> <span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">cart_coords</span><span class="p">),</span> <span class="s2">&quot;label&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">label</span><span class="p">,</span>
                <span class="s2">&quot;@module&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__module__</span><span class="p">,</span>
                <span class="s2">&quot;@class&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">}</span></div></div>


<div class="viewcode-block" id="BandStructure"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.bandstructure.html#pymatgen.electronic_structure.bandstructure.BandStructure">[docs]</a><span class="k">class</span> <span class="nc">BandStructure</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    This is the most generic band structure data possible</span>
<span class="sd">    it&#39;s defined by a list of kpoints + energies for each of them</span>

<span class="sd">    .. attribute:: kpoints:</span>
<span class="sd">        the list of kpoints (as Kpoint objects) in the band structure</span>

<span class="sd">    .. attribute:: lattice_rec</span>

<span class="sd">        the reciprocal lattice of the band structure.</span>

<span class="sd">    .. attribute:: efermi</span>

<span class="sd">        the fermi energy</span>

<span class="sd">    .. attribute::  is_spin_polarized</span>

<span class="sd">        True if the band structure is spin-polarized, False otherwise</span>

<span class="sd">    .. attribute:: bands</span>

<span class="sd">        The energy eigenvalues as a {spin: ndarray}. Note that the use of an</span>
<span class="sd">        ndarray is necessary for computational as well as memory efficiency</span>
<span class="sd">        due to the large amount of numerical data. The indices of the ndarray</span>
<span class="sd">        are [band_index, kpoint_index].</span>

<span class="sd">    .. attribute:: nb_bands</span>

<span class="sd">        returns the number of bands in the band structure</span>

<span class="sd">    .. attribute:: structure</span>

<span class="sd">        returns the structure</span>

<span class="sd">    .. attribute:: projections</span>

<span class="sd">        The projections as a {spin: ndarray}. Note that the use of an</span>
<span class="sd">        ndarray is necessary for computational as well as memory efficiency</span>
<span class="sd">        due to the large amount of numerical data. The indices of the ndarray</span>
<span class="sd">        are [band_index, kpoint_index, orbital_index, ion_index].</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">kpoints</span><span class="p">,</span> <span class="n">eigenvals</span><span class="p">,</span> <span class="n">lattice</span><span class="p">,</span> <span class="n">efermi</span><span class="p">,</span> <span class="n">labels_dict</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">coords_are_cartesian</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">structure</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">projections</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            kpoints: list of kpoint as numpy arrays, in frac_coords of the</span>
<span class="sd">                given lattice by default</span>
<span class="sd">            eigenvals: dict of energies for spin up and spin down</span>
<span class="sd">                {Spin.up:[][],Spin.down:[][]}, the first index of the array</span>
<span class="sd">                [][] refers to the band and the second to the index of the</span>
<span class="sd">                kpoint. The kpoints are ordered according to the order of the</span>
<span class="sd">                kpoints array. If the band structure is not spin polarized, we</span>
<span class="sd">                only store one data set under Spin.up</span>
<span class="sd">            lattice: The reciprocal lattice as a pymatgen Lattice object.</span>
<span class="sd">                Pymatgen uses the physics convention of reciprocal lattice vectors</span>
<span class="sd">                WITH a 2*pi coefficient</span>
<span class="sd">            efermi: fermi energy</span>
<span class="sd">            labels_dict: (dict) of {} this links a kpoint (in frac coords or</span>
<span class="sd">                cartesian coordinates depending on the coords) to a label.</span>
<span class="sd">            coords_are_cartesian: Whether coordinates are cartesian.</span>
<span class="sd">            structure: The crystal structure (as a pymatgen Structure object)</span>
<span class="sd">                associated with the band structure. This is needed if we</span>
<span class="sd">                provide projections to the band structure</span>
<span class="sd">            projections: dict of orbital projections as {spin: ndarray}. The</span>
<span class="sd">                indices of the ndarrayare [band_index, kpoint_index, orbital_index,</span>
<span class="sd">                ion_index].If the band structure is not spin polarized, we only</span>
<span class="sd">                store one data set under Spin.up.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span> <span class="o">=</span> <span class="n">efermi</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">lattice_rec</span> <span class="o">=</span> <span class="n">lattice</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">kpoints</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">labels_dict</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">structure</span> <span class="o">=</span> <span class="n">structure</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">projections</span> <span class="o">=</span> <span class="n">projections</span> <span class="ow">or</span> <span class="p">{}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">projections</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">projections</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>

        <span class="k">if</span> <span class="n">labels_dict</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">labels_dict</span> <span class="o">=</span> <span class="p">{}</span>

        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">projections</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">0</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s2">&quot;if projections are provided a structure object&quot;</span>
                            <span class="s2">&quot; needs also to be given&quot;</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">kpoints</span><span class="p">:</span>
            <span class="c1"># let see if this kpoint has been assigned a label</span>
            <span class="n">label</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">labels_dict</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span><span class="n">k</span> <span class="o">-</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">labels_dict</span><span class="p">[</span><span class="n">c</span><span class="p">]))</span> <span class="o">&lt;</span> <span class="mf">0.0001</span><span class="p">:</span>
                    <span class="n">label</span> <span class="o">=</span> <span class="n">c</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">labels_dict</span><span class="p">[</span><span class="n">label</span><span class="p">]</span> <span class="o">=</span> <span class="n">Kpoint</span><span class="p">(</span>
                        <span class="n">k</span><span class="p">,</span> <span class="n">lattice</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">,</span>
                        <span class="n">coords_are_cartesian</span><span class="o">=</span><span class="n">coords_are_cartesian</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">kpoints</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                <span class="n">Kpoint</span><span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="n">lattice</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">,</span>
                       <span class="n">coords_are_cartesian</span><span class="o">=</span><span class="n">coords_are_cartesian</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bands</span> <span class="o">=</span> <span class="p">{</span><span class="n">spin</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">eigenvals</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">nb_bands</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">eigenvals</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">is_spin_polarized</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">bands</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span>

<div class="viewcode-block" id="BandStructure.get_projection_on_elements"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.bandstructure.html#pymatgen.electronic_structure.bandstructure.BandStructure.get_projection_on_elements">[docs]</a>    <span class="k">def</span> <span class="nf">get_projection_on_elements</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Method returning a dictionary of projections on elements.</span>

<span class="sd">        Returns:</span>
<span class="sd">            a dictionary in the {Spin.up:[][{Element:values}],</span>
<span class="sd">            Spin.down:[][{Element:values}]} format</span>
<span class="sd">            if there is no projections in the band structure</span>
<span class="sd">            returns an empty dict</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">result</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="n">structure</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure</span>
        <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">projections</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="n">result</span><span class="p">[</span><span class="n">spin</span><span class="p">]</span> <span class="o">=</span> <span class="p">[[</span><span class="n">collections</span><span class="o">.</span><span class="n">defaultdict</span><span class="p">(</span><span class="nb">float</span><span class="p">)</span>
                             <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">kpoints</span><span class="p">))]</span>
                            <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nb_bands</span><span class="p">)]</span>
            <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">j</span><span class="p">,</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">itertools</span><span class="o">.</span><span class="n">product</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nb_bands</span><span class="p">),</span>
                                             <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">kpoints</span><span class="p">)),</span>
                                             <span class="nb">range</span><span class="p">(</span><span class="n">structure</span><span class="o">.</span><span class="n">num_sites</span><span class="p">)):</span>
                <span class="n">result</span><span class="p">[</span><span class="n">spin</span><span class="p">][</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="nb">str</span><span class="p">(</span><span class="n">structure</span><span class="p">[</span><span class="n">k</span><span class="p">]</span><span class="o">.</span><span class="n">specie</span><span class="p">)]</span> <span class="o">+=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span>
                    <span class="n">v</span><span class="p">[</span><span class="n">i</span><span class="p">,</span> <span class="n">j</span><span class="p">,</span> <span class="p">:,</span> <span class="n">k</span><span class="p">])</span>
        <span class="k">return</span> <span class="n">result</span></div>

<div class="viewcode-block" id="BandStructure.get_projections_on_elements_and_orbitals"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.bandstructure.html#pymatgen.electronic_structure.bandstructure.BandStructure.get_projections_on_elements_and_orbitals">[docs]</a>    <span class="k">def</span> <span class="nf">get_projections_on_elements_and_orbitals</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">el_orb_spec</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Method returning a dictionary of projections on elements and specific</span>
<span class="sd">        orbitals</span>

<span class="sd">        Args:</span>
<span class="sd">            el_orb_spec: A dictionary of Elements and Orbitals for which we want</span>
<span class="sd">                to have projections on. It is given as: {Element:[orbitals]},</span>
<span class="sd">                e.g., {&#39;Cu&#39;:[&#39;d&#39;,&#39;s&#39;]}</span>

<span class="sd">        Returns:</span>
<span class="sd">            A dictionary of projections on elements in the</span>
<span class="sd">            {Spin.up:[][{Element:{orb:values}}],</span>
<span class="sd">            Spin.down:[][{Element:{orb:values}}]} format</span>
<span class="sd">            if there is no projections in the band structure returns an empty</span>
<span class="sd">            dict.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">result</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="n">structure</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure</span>
        <span class="n">el_orb_spec</span> <span class="o">=</span> <span class="p">{</span><span class="n">get_el_sp</span><span class="p">(</span><span class="n">el</span><span class="p">):</span> <span class="n">orbs</span> <span class="k">for</span> <span class="n">el</span><span class="p">,</span> <span class="n">orbs</span> <span class="ow">in</span> <span class="n">el_orb_spec</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
        <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">projections</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="n">result</span><span class="p">[</span><span class="n">spin</span><span class="p">]</span> <span class="o">=</span> <span class="p">[[{</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">):</span> <span class="n">collections</span><span class="o">.</span><span class="n">defaultdict</span><span class="p">(</span><span class="nb">float</span><span class="p">)</span>
                              <span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="n">el_orb_spec</span><span class="p">}</span>
                             <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">kpoints</span><span class="p">))]</span>
                            <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nb_bands</span><span class="p">)]</span>

            <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">j</span><span class="p">,</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">itertools</span><span class="o">.</span><span class="n">product</span><span class="p">(</span>
                    <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nb_bands</span><span class="p">),</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">kpoints</span><span class="p">)),</span>
                    <span class="nb">range</span><span class="p">(</span><span class="n">structure</span><span class="o">.</span><span class="n">num_sites</span><span class="p">)):</span>
                <span class="n">sp</span> <span class="o">=</span> <span class="n">structure</span><span class="p">[</span><span class="n">k</span><span class="p">]</span><span class="o">.</span><span class="n">specie</span>
                <span class="k">for</span> <span class="n">orb_i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">v</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">])):</span>
                    <span class="n">o</span> <span class="o">=</span> <span class="n">Orbital</span><span class="p">(</span><span class="n">orb_i</span><span class="p">)</span><span class="o">.</span><span class="n">name</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
                    <span class="k">if</span> <span class="n">sp</span> <span class="ow">in</span> <span class="n">el_orb_spec</span><span class="p">:</span>
                        <span class="k">if</span> <span class="n">o</span> <span class="ow">in</span> <span class="n">el_orb_spec</span><span class="p">[</span><span class="n">sp</span><span class="p">]:</span>
                            <span class="n">result</span><span class="p">[</span><span class="n">spin</span><span class="p">][</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="nb">str</span><span class="p">(</span><span class="n">sp</span><span class="p">)][</span><span class="n">o</span><span class="p">]</span> <span class="o">+=</span> <span class="n">v</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span>
                                <span class="n">orb_i</span><span class="p">][</span><span class="n">k</span><span class="p">]</span>
        <span class="k">return</span> <span class="n">result</span></div>

<div class="viewcode-block" id="BandStructure.is_metal"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.bandstructure.html#pymatgen.electronic_structure.bandstructure.BandStructure.is_metal">[docs]</a>    <span class="k">def</span> <span class="nf">is_metal</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">efermi_tol</span><span class="o">=</span><span class="mf">1e-4</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Check if the band structure indicates a metal by looking if the fermi</span>
<span class="sd">        level crosses a band.</span>

<span class="sd">        Returns:</span>
<span class="sd">            True if a metal, False if not</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">values</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bands</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nb_bands</span><span class="p">):</span>
                <span class="k">if</span> <span class="n">np</span><span class="o">.</span><span class="n">any</span><span class="p">(</span><span class="n">values</span><span class="p">[</span><span class="n">i</span><span class="p">,</span> <span class="p">:]</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span> <span class="o">&lt;</span> <span class="o">-</span><span class="n">efermi_tol</span><span class="p">)</span> <span class="ow">and</span> \
                        <span class="n">np</span><span class="o">.</span><span class="n">any</span><span class="p">(</span><span class="n">values</span><span class="p">[</span><span class="n">i</span><span class="p">,</span> <span class="p">:]</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span> <span class="o">&gt;</span> <span class="n">efermi_tol</span><span class="p">):</span>
                    <span class="k">return</span> <span class="kc">True</span>
        <span class="k">return</span> <span class="kc">False</span></div>

<div class="viewcode-block" id="BandStructure.get_vbm"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.bandstructure.html#pymatgen.electronic_structure.bandstructure.BandStructure.get_vbm">[docs]</a>    <span class="k">def</span> <span class="nf">get_vbm</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns data about the VBM.</span>

<span class="sd">        Returns:</span>
<span class="sd">            dict as {&quot;band_index&quot;,&quot;kpoint_index&quot;,&quot;kpoint&quot;,&quot;energy&quot;}</span>
<span class="sd">            - &quot;band_index&quot;: A dict with spin keys pointing to a list of the</span>
<span class="sd">            indices of the band containing the VBM (please note that you</span>
<span class="sd">            can have several bands sharing the VBM) {Spin.up:[],</span>
<span class="sd">            Spin.down:[]}</span>
<span class="sd">            - &quot;kpoint_index&quot;: The list of indices in self.kpoints for the</span>
<span class="sd">            kpoint vbm. Please note that there can be several</span>
<span class="sd">            kpoint_indices relating to the same kpoint (e.g., Gamma can</span>
<span class="sd">            occur at different spots in the band structure line plot)</span>
<span class="sd">            - &quot;kpoint&quot;: The kpoint (as a kpoint object)</span>
<span class="sd">            - &quot;energy&quot;: The energy of the VBM</span>
<span class="sd">            - &quot;projections&quot;: The projections along sites and orbitals of the</span>
<span class="sd">            VBM if any projection data is available (else it is an empty</span>
<span class="sd">            dictionnary). The format is similar to the projections field in</span>
<span class="sd">            BandStructure: {spin:{&#39;Orbital&#39;: [proj]}} where the array</span>
<span class="sd">            [proj] is ordered according to the sites in structure</span>
<span class="sd">    &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_metal</span><span class="p">():</span>
            <span class="k">return</span> <span class="p">{</span><span class="s2">&quot;band_index&quot;</span><span class="p">:</span> <span class="p">[],</span> <span class="s2">&quot;kpoint_index&quot;</span><span class="p">:</span> <span class="p">[],</span>
                    <span class="s2">&quot;kpoint&quot;</span><span class="p">:</span> <span class="p">[],</span> <span class="s2">&quot;energy&quot;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span> <span class="s2">&quot;projections&quot;</span><span class="p">:</span> <span class="p">{}}</span>
        <span class="n">max_tmp</span> <span class="o">=</span> <span class="o">-</span><span class="nb">float</span><span class="p">(</span><span class="s2">&quot;inf&quot;</span><span class="p">)</span>
        <span class="n">index</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="n">kpointvbm</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bands</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">v</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span><span class="p">)):</span>
                <span class="k">if</span> <span class="n">v</span><span class="p">[</span><span class="n">i</span><span class="p">,</span> <span class="n">j</span><span class="p">]</span> <span class="o">&gt;</span> <span class="n">max_tmp</span><span class="p">:</span>
                    <span class="n">max_tmp</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">v</span><span class="p">[</span><span class="n">i</span><span class="p">,</span> <span class="n">j</span><span class="p">])</span>
                    <span class="n">index</span> <span class="o">=</span> <span class="n">j</span>
                    <span class="n">kpointvbm</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">kpoints</span><span class="p">[</span><span class="n">j</span><span class="p">]</span>

        <span class="n">list_ind_kpts</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">if</span> <span class="n">kpointvbm</span><span class="o">.</span><span class="n">label</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">kpoints</span><span class="p">)):</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">kpoints</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">label</span> <span class="o">==</span> <span class="n">kpointvbm</span><span class="o">.</span><span class="n">label</span><span class="p">:</span>
                    <span class="n">list_ind_kpts</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">list_ind_kpts</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">index</span><span class="p">)</span>
        <span class="c1"># get all other bands sharing the vbm</span>
        <span class="n">list_ind_band</span> <span class="o">=</span> <span class="n">collections</span><span class="o">.</span><span class="n">defaultdict</span><span class="p">(</span><span class="nb">list</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">spin</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bands</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nb_bands</span><span class="p">):</span>
                <span class="k">if</span> <span class="n">math</span><span class="o">.</span><span class="n">fabs</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">bands</span><span class="p">[</span><span class="n">spin</span><span class="p">][</span><span class="n">i</span><span class="p">][</span><span class="n">index</span><span class="p">]</span> <span class="o">-</span> <span class="n">max_tmp</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mf">0.001</span><span class="p">:</span>
                    <span class="n">list_ind_band</span><span class="p">[</span><span class="n">spin</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
        <span class="n">proj</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">projections</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">list_ind_band</span><span class="p">[</span><span class="n">spin</span><span class="p">])</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
                <span class="k">continue</span>
            <span class="n">proj</span><span class="p">[</span><span class="n">spin</span><span class="p">]</span> <span class="o">=</span> <span class="n">v</span><span class="p">[</span><span class="n">list_ind_band</span><span class="p">[</span><span class="n">spin</span><span class="p">][</span><span class="mi">0</span><span class="p">]][</span><span class="n">list_ind_kpts</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span>
        <span class="k">return</span> <span class="p">{</span><span class="s1">&#39;band_index&#39;</span><span class="p">:</span> <span class="n">list_ind_band</span><span class="p">,</span>
                <span class="s1">&#39;kpoint_index&#39;</span><span class="p">:</span> <span class="n">list_ind_kpts</span><span class="p">,</span>
                <span class="s1">&#39;kpoint&#39;</span><span class="p">:</span> <span class="n">kpointvbm</span><span class="p">,</span> <span class="s1">&#39;energy&#39;</span><span class="p">:</span> <span class="n">max_tmp</span><span class="p">,</span>
                <span class="s1">&#39;projections&#39;</span><span class="p">:</span> <span class="n">proj</span><span class="p">}</span></div>

<div class="viewcode-block" id="BandStructure.get_cbm"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.bandstructure.html#pymatgen.electronic_structure.bandstructure.BandStructure.get_cbm">[docs]</a>    <span class="k">def</span> <span class="nf">get_cbm</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns data about the CBM.</span>

<span class="sd">        Returns:</span>
<span class="sd">            {&quot;band_index&quot;,&quot;kpoint_index&quot;,&quot;kpoint&quot;,&quot;energy&quot;}</span>
<span class="sd">            - &quot;band_index&quot;: A dict with spin keys pointing to a list of the</span>
<span class="sd">            indices of the band containing the VBM (please note that you</span>
<span class="sd">            can have several bands sharing the VBM) {Spin.up:[],</span>
<span class="sd">            Spin.down:[]}</span>
<span class="sd">            - &quot;kpoint_index&quot;: The list of indices in self.kpoints for the</span>
<span class="sd">            kpoint vbm. Please note that there can be several</span>
<span class="sd">            kpoint_indices relating to the same kpoint (e.g., Gamma can</span>
<span class="sd">            occur at different spots in the band structure line plot)</span>
<span class="sd">            - &quot;kpoint&quot;: The kpoint (as a kpoint object)</span>
<span class="sd">            - &quot;energy&quot;: The energy of the VBM</span>
<span class="sd">            - &quot;projections&quot;: The projections along sites and orbitals of the</span>
<span class="sd">            VBM if any projection data is available (else it is an empty</span>
<span class="sd">            dictionnary). The format is similar to the projections field in</span>
<span class="sd">            BandStructure: {spin:{&#39;Orbital&#39;: [proj]}} where the array</span>
<span class="sd">            [proj] is ordered according to the sites in structure</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_metal</span><span class="p">():</span>
            <span class="k">return</span> <span class="p">{</span><span class="s2">&quot;band_index&quot;</span><span class="p">:</span> <span class="p">[],</span> <span class="s2">&quot;kpoint_index&quot;</span><span class="p">:</span> <span class="p">[],</span>
                    <span class="s2">&quot;kpoint&quot;</span><span class="p">:</span> <span class="p">[],</span> <span class="s2">&quot;energy&quot;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span> <span class="s2">&quot;projections&quot;</span><span class="p">:</span> <span class="p">{}}</span>
        <span class="n">max_tmp</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="s2">&quot;inf&quot;</span><span class="p">)</span>

        <span class="n">index</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="n">kpointcbm</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bands</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">v</span> <span class="o">&gt;=</span> <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span><span class="p">)):</span>
                <span class="k">if</span> <span class="n">v</span><span class="p">[</span><span class="n">i</span><span class="p">,</span> <span class="n">j</span><span class="p">]</span> <span class="o">&lt;</span> <span class="n">max_tmp</span><span class="p">:</span>
                    <span class="n">max_tmp</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">v</span><span class="p">[</span><span class="n">i</span><span class="p">,</span> <span class="n">j</span><span class="p">])</span>
                    <span class="n">index</span> <span class="o">=</span> <span class="n">j</span>
                    <span class="n">kpointcbm</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">kpoints</span><span class="p">[</span><span class="n">j</span><span class="p">]</span>

        <span class="n">list_index_kpoints</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">if</span> <span class="n">kpointcbm</span><span class="o">.</span><span class="n">label</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">kpoints</span><span class="p">)):</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">kpoints</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">label</span> <span class="o">==</span> <span class="n">kpointcbm</span><span class="o">.</span><span class="n">label</span><span class="p">:</span>
                    <span class="n">list_index_kpoints</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">list_index_kpoints</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">index</span><span class="p">)</span>

        <span class="c1"># get all other bands sharing the cbm</span>
        <span class="n">list_index_band</span> <span class="o">=</span> <span class="n">collections</span><span class="o">.</span><span class="n">defaultdict</span><span class="p">(</span><span class="nb">list</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">spin</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bands</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nb_bands</span><span class="p">):</span>
                <span class="k">if</span> <span class="n">math</span><span class="o">.</span><span class="n">fabs</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">bands</span><span class="p">[</span><span class="n">spin</span><span class="p">][</span><span class="n">i</span><span class="p">][</span><span class="n">index</span><span class="p">]</span> <span class="o">-</span> <span class="n">max_tmp</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mf">0.001</span><span class="p">:</span>
                    <span class="n">list_index_band</span><span class="p">[</span><span class="n">spin</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
        <span class="n">proj</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">projections</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">list_index_band</span><span class="p">[</span><span class="n">spin</span><span class="p">])</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
                <span class="k">continue</span>
            <span class="n">proj</span><span class="p">[</span><span class="n">spin</span><span class="p">]</span> <span class="o">=</span> <span class="n">v</span><span class="p">[</span><span class="n">list_index_band</span><span class="p">[</span><span class="n">spin</span><span class="p">][</span><span class="mi">0</span><span class="p">]][</span><span class="n">list_index_kpoints</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span>

        <span class="k">return</span> <span class="p">{</span><span class="s1">&#39;band_index&#39;</span><span class="p">:</span> <span class="n">list_index_band</span><span class="p">,</span>
                <span class="s1">&#39;kpoint_index&#39;</span><span class="p">:</span> <span class="n">list_index_kpoints</span><span class="p">,</span>
                <span class="s1">&#39;kpoint&#39;</span><span class="p">:</span> <span class="n">kpointcbm</span><span class="p">,</span> <span class="s1">&#39;energy&#39;</span><span class="p">:</span> <span class="n">max_tmp</span><span class="p">,</span>
                <span class="s1">&#39;projections&#39;</span><span class="p">:</span> <span class="n">proj</span><span class="p">}</span></div>

<div class="viewcode-block" id="BandStructure.get_band_gap"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.bandstructure.html#pymatgen.electronic_structure.bandstructure.BandStructure.get_band_gap">[docs]</a>    <span class="k">def</span> <span class="nf">get_band_gap</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sa">r</span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns band gap data.</span>

<span class="sd">        Returns:</span>
<span class="sd">            A dict {&quot;energy&quot;,&quot;direct&quot;,&quot;transition&quot;}:</span>
<span class="sd">            &quot;energy&quot;: band gap energy</span>
<span class="sd">            &quot;direct&quot;: A boolean telling if the gap is direct or not</span>
<span class="sd">            &quot;transition&quot;: kpoint labels of the transition (e.g., &quot;\\Gamma-X&quot;)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_metal</span><span class="p">():</span>
            <span class="k">return</span> <span class="p">{</span><span class="s2">&quot;energy&quot;</span><span class="p">:</span> <span class="mf">0.0</span><span class="p">,</span> <span class="s2">&quot;direct&quot;</span><span class="p">:</span> <span class="kc">False</span><span class="p">,</span> <span class="s2">&quot;transition&quot;</span><span class="p">:</span> <span class="kc">None</span><span class="p">}</span>
        <span class="n">cbm</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_cbm</span><span class="p">()</span>
        <span class="n">vbm</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_vbm</span><span class="p">()</span>
        <span class="n">result</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="n">direct</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">energy</span><span class="o">=</span><span class="mf">0.0</span><span class="p">,</span> <span class="n">transition</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span>

        <span class="n">result</span><span class="p">[</span><span class="s2">&quot;energy&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">cbm</span><span class="p">[</span><span class="s2">&quot;energy&quot;</span><span class="p">]</span> <span class="o">-</span> <span class="n">vbm</span><span class="p">[</span><span class="s2">&quot;energy&quot;</span><span class="p">]</span>

        <span class="k">if</span> <span class="p">(</span><span class="n">cbm</span><span class="p">[</span><span class="s2">&quot;kpoint&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">label</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">cbm</span><span class="p">[</span><span class="s2">&quot;kpoint&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">label</span> <span class="o">==</span> <span class="n">vbm</span><span class="p">[</span>
            <span class="s2">&quot;kpoint&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">label</span><span class="p">)</span> \
                <span class="ow">or</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span><span class="n">cbm</span><span class="p">[</span><span class="s2">&quot;kpoint&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">cart_coords</span>
                                  <span class="o">-</span> <span class="n">vbm</span><span class="p">[</span><span class="s2">&quot;kpoint&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">cart_coords</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mf">0.01</span><span class="p">:</span>
            <span class="n">result</span><span class="p">[</span><span class="s2">&quot;direct&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="kc">True</span>

        <span class="n">result</span><span class="p">[</span><span class="s2">&quot;transition&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;-&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span>
            <span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">label</span><span class="p">)</span> <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">label</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="k">else</span>
             <span class="nb">str</span><span class="p">(</span><span class="s2">&quot;(&quot;</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;,&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="s2">&quot;</span><span class="si">{0:.3f}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">frac_coords</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
                                  <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">3</span><span class="p">)])</span>
             <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="s2">&quot;)&quot;</span><span class="p">)</span> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="p">[</span><span class="n">vbm</span><span class="p">[</span><span class="s2">&quot;kpoint&quot;</span><span class="p">],</span> <span class="n">cbm</span><span class="p">[</span><span class="s2">&quot;kpoint&quot;</span><span class="p">]]])</span>

        <span class="k">return</span> <span class="n">result</span></div>

<div class="viewcode-block" id="BandStructure.get_direct_band_gap_dict"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.bandstructure.html#pymatgen.electronic_structure.bandstructure.BandStructure.get_direct_band_gap_dict">[docs]</a>    <span class="k">def</span> <span class="nf">get_direct_band_gap_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns a dictionary of information about the direct</span>
<span class="sd">        band gap</span>

<span class="sd">        Returns:</span>
<span class="sd">            a dictionary of the band gaps indexed by spin</span>
<span class="sd">            along with their band indices and k-point index</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_metal</span><span class="p">():</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;get_direct_band_gap_dict should&quot;</span>
                             <span class="s2">&quot;only be used with non-metals&quot;</span><span class="p">)</span>
        <span class="n">direct_gap_dict</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bands</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="n">above</span> <span class="o">=</span> <span class="n">v</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">all</span><span class="p">(</span><span class="n">v</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)]</span>
            <span class="n">min_above</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">min</span><span class="p">(</span><span class="n">above</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
            <span class="n">below</span> <span class="o">=</span> <span class="n">v</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">all</span><span class="p">(</span><span class="n">v</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)]</span>
            <span class="n">max_below</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">below</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
            <span class="n">diff</span> <span class="o">=</span> <span class="n">min_above</span> <span class="o">-</span> <span class="n">max_below</span>
            <span class="n">kpoint_index</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">argmin</span><span class="p">(</span><span class="n">diff</span><span class="p">)</span>
            <span class="n">band_indices</span> <span class="o">=</span> <span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">argmax</span><span class="p">(</span><span class="n">below</span><span class="p">[:,</span> <span class="n">kpoint_index</span><span class="p">]),</span>
                            <span class="n">np</span><span class="o">.</span><span class="n">argmin</span><span class="p">(</span><span class="n">above</span><span class="p">[:,</span> <span class="n">kpoint_index</span><span class="p">])</span> <span class="o">+</span> <span class="nb">len</span><span class="p">(</span><span class="n">below</span><span class="p">)]</span>
            <span class="n">direct_gap_dict</span><span class="p">[</span><span class="n">spin</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;value&quot;</span><span class="p">:</span> <span class="n">diff</span><span class="p">[</span><span class="n">kpoint_index</span><span class="p">],</span>
                                     <span class="s2">&quot;kpoint_index&quot;</span><span class="p">:</span> <span class="n">kpoint_index</span><span class="p">,</span>
                                     <span class="s2">&quot;band_indices&quot;</span><span class="p">:</span> <span class="n">band_indices</span><span class="p">}</span>
        <span class="k">return</span> <span class="n">direct_gap_dict</span></div>

<div class="viewcode-block" id="BandStructure.get_direct_band_gap"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.bandstructure.html#pymatgen.electronic_structure.bandstructure.BandStructure.get_direct_band_gap">[docs]</a>    <span class="k">def</span> <span class="nf">get_direct_band_gap</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the direct band gap.</span>

<span class="sd">        Returns:</span>
<span class="sd">             the value of the direct band gap</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_metal</span><span class="p">():</span>
            <span class="k">return</span> <span class="mf">0.0</span>
        <span class="n">dg</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_direct_band_gap_dict</span><span class="p">()</span>
        <span class="k">return</span> <span class="nb">min</span><span class="p">(</span><span class="n">v</span><span class="p">[</span><span class="s1">&#39;value&#39;</span><span class="p">]</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">dg</span><span class="o">.</span><span class="n">values</span><span class="p">())</span></div>

<div class="viewcode-block" id="BandStructure.get_sym_eq_kpoints"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.bandstructure.html#pymatgen.electronic_structure.bandstructure.BandStructure.get_sym_eq_kpoints">[docs]</a>    <span class="k">def</span> <span class="nf">get_sym_eq_kpoints</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">kpoint</span><span class="p">,</span> <span class="n">cartesian</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">tol</span><span class="o">=</span><span class="mf">1e-2</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns a list of unique symmetrically equivalent k-points.</span>

<span class="sd">        Args:</span>
<span class="sd">            kpoint (1x3 array): coordinate of the k-point</span>
<span class="sd">            cartesian (bool): kpoint is in cartesian or fractional coordinates</span>
<span class="sd">            tol (float): tolerance below which coordinates are considered equal</span>

<span class="sd">        Returns:</span>
<span class="sd">            ([1x3 array] or None): if structure is not available returns None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">None</span>
        <span class="n">sg</span> <span class="o">=</span> <span class="n">SpacegroupAnalyzer</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">)</span>
        <span class="n">symmops</span> <span class="o">=</span> <span class="n">sg</span><span class="o">.</span><span class="n">get_point_group_operations</span><span class="p">(</span><span class="n">cartesian</span><span class="o">=</span><span class="n">cartesian</span><span class="p">)</span>
        <span class="n">points</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">kpoint</span><span class="p">,</span> <span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">rotation_matrix</span> <span class="k">for</span> <span class="n">m</span> <span class="ow">in</span> <span class="n">symmops</span><span class="p">])</span>
        <span class="n">rm_list</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="c1"># identify and remove duplicates from the list of equivalent k-points:</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">points</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">):</span>
            <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">points</span><span class="p">)):</span>
                <span class="k">if</span> <span class="n">np</span><span class="o">.</span><span class="n">allclose</span><span class="p">(</span><span class="n">pbc_diff</span><span class="p">(</span><span class="n">points</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">points</span><span class="p">[</span><span class="n">j</span><span class="p">]),</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="n">tol</span><span class="p">):</span>
                    <span class="n">rm_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
                    <span class="k">break</span>
        <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">delete</span><span class="p">(</span><span class="n">points</span><span class="p">,</span> <span class="n">rm_list</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span></div>

<div class="viewcode-block" id="BandStructure.get_kpoint_degeneracy"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.bandstructure.html#pymatgen.electronic_structure.bandstructure.BandStructure.get_kpoint_degeneracy">[docs]</a>    <span class="k">def</span> <span class="nf">get_kpoint_degeneracy</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">kpoint</span><span class="p">,</span> <span class="n">cartesian</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">tol</span><span class="o">=</span><span class="mf">1e-2</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns degeneracy of a given k-point based on structure symmetry</span>
<span class="sd">        Args:</span>
<span class="sd">            kpoint (1x3 array): coordinate of the k-point</span>
<span class="sd">            cartesian (bool): kpoint is in cartesian or fractional coordinates</span>
<span class="sd">            tol (float): tolerance below which coordinates are considered equal</span>

<span class="sd">        Returns:</span>
<span class="sd">            (int or None): degeneracy or None if structure is not available</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">all_kpts</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_sym_eq_kpoints</span><span class="p">(</span><span class="n">kpoint</span><span class="p">,</span> <span class="n">cartesian</span><span class="p">,</span> <span class="n">tol</span><span class="o">=</span><span class="n">tol</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">all_kpts</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="n">all_kpts</span><span class="p">)</span></div>

<div class="viewcode-block" id="BandStructure.as_dict"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.bandstructure.html#pymatgen.electronic_structure.bandstructure.BandStructure.as_dict">[docs]</a>    <span class="k">def</span> <span class="nf">as_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Json-serializable dict representation of BandStructureSymmLine.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">d</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;@module&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__module__</span><span class="p">,</span>
             <span class="s2">&quot;@class&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span>
             <span class="s2">&quot;lattice_rec&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">lattice_rec</span><span class="o">.</span><span class="n">as_dict</span><span class="p">(),</span> <span class="s2">&quot;efermi&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span><span class="p">,</span>
             <span class="s2">&quot;kpoints&quot;</span><span class="p">:</span> <span class="p">[]}</span>
        <span class="c1"># kpoints are not kpoint objects dicts but are frac coords (this makes</span>
        <span class="c1"># the dict smaller and avoids the repetition of the lattice</span>
        <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">kpoints</span><span class="p">:</span>
            <span class="n">d</span><span class="p">[</span><span class="s2">&quot;kpoints&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">k</span><span class="o">.</span><span class="n">as_dict</span><span class="p">()[</span><span class="s2">&quot;fcoords&quot;</span><span class="p">])</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;bands&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="nb">str</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">spin</span><span class="p">)):</span> <span class="bp">self</span><span class="o">.</span><span class="n">bands</span><span class="p">[</span><span class="n">spin</span><span class="p">]</span>
                      <span class="k">for</span> <span class="n">spin</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bands</span><span class="p">}</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;is_metal&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_metal</span><span class="p">()</span>
        <span class="n">vbm</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_vbm</span><span class="p">()</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;vbm&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;energy&quot;</span><span class="p">:</span> <span class="n">vbm</span><span class="p">[</span><span class="s2">&quot;energy&quot;</span><span class="p">],</span>
                    <span class="s2">&quot;kpoint_index&quot;</span><span class="p">:</span> <span class="n">vbm</span><span class="p">[</span><span class="s2">&quot;kpoint_index&quot;</span><span class="p">],</span>
                    <span class="s2">&quot;band_index&quot;</span><span class="p">:</span> <span class="p">{</span><span class="nb">str</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">spin</span><span class="p">)):</span> <span class="n">vbm</span><span class="p">[</span><span class="s2">&quot;band_index&quot;</span><span class="p">][</span><span class="n">spin</span><span class="p">]</span>
                                   <span class="k">for</span> <span class="n">spin</span> <span class="ow">in</span> <span class="n">vbm</span><span class="p">[</span><span class="s2">&quot;band_index&quot;</span><span class="p">]},</span>
                    <span class="s1">&#39;projections&#39;</span><span class="p">:</span> <span class="p">{</span><span class="nb">str</span><span class="p">(</span><span class="n">spin</span><span class="p">):</span> <span class="n">v</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span> <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">vbm</span><span class="p">[</span>
                        <span class="s1">&#39;projections&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">()}}</span>
        <span class="n">cbm</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_cbm</span><span class="p">()</span>
        <span class="n">d</span><span class="p">[</span><span class="s1">&#39;cbm&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;energy&#39;</span><span class="p">:</span> <span class="n">cbm</span><span class="p">[</span><span class="s1">&#39;energy&#39;</span><span class="p">],</span>
                    <span class="s1">&#39;kpoint_index&#39;</span><span class="p">:</span> <span class="n">cbm</span><span class="p">[</span><span class="s1">&#39;kpoint_index&#39;</span><span class="p">],</span>
                    <span class="s1">&#39;band_index&#39;</span><span class="p">:</span> <span class="p">{</span><span class="nb">str</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">spin</span><span class="p">)):</span> <span class="n">cbm</span><span class="p">[</span><span class="s1">&#39;band_index&#39;</span><span class="p">][</span><span class="n">spin</span><span class="p">]</span>
                                   <span class="k">for</span> <span class="n">spin</span> <span class="ow">in</span> <span class="n">cbm</span><span class="p">[</span><span class="s1">&#39;band_index&#39;</span><span class="p">]},</span>
                    <span class="s1">&#39;projections&#39;</span><span class="p">:</span> <span class="p">{</span><span class="nb">str</span><span class="p">(</span><span class="n">spin</span><span class="p">):</span> <span class="n">v</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span> <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">cbm</span><span class="p">[</span>
                        <span class="s1">&#39;projections&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">()}}</span>
        <span class="n">d</span><span class="p">[</span><span class="s1">&#39;band_gap&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_band_gap</span><span class="p">()</span>
        <span class="n">d</span><span class="p">[</span><span class="s1">&#39;labels_dict&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="n">d</span><span class="p">[</span><span class="s1">&#39;is_spin_polarized&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_spin_polarized</span>
        <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">labels_dict</span><span class="p">:</span>
            <span class="n">d</span><span class="p">[</span><span class="s1">&#39;labels_dict&#39;</span><span class="p">][</span><span class="n">c</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">labels_dict</span><span class="p">[</span><span class="n">c</span><span class="p">]</span><span class="o">.</span><span class="n">as_dict</span><span class="p">()[</span><span class="s1">&#39;fcoords&#39;</span><span class="p">]</span>
        <span class="n">d</span><span class="p">[</span><span class="s1">&#39;projections&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">projections</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">d</span><span class="p">[</span><span class="s1">&#39;structure&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="o">.</span><span class="n">as_dict</span><span class="p">()</span>
            <span class="n">d</span><span class="p">[</span><span class="s1">&#39;projections&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="nb">str</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">spin</span><span class="p">)):</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">v</span><span class="p">)</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
                                <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">projections</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
        <span class="k">return</span> <span class="n">d</span></div>

<div class="viewcode-block" id="BandStructure.from_dict"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.bandstructure.html#pymatgen.electronic_structure.bandstructure.BandStructure.from_dict">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_dict</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">d</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Create from dict.</span>

<span class="sd">        Args:</span>
<span class="sd">            A dict with all data for a band structure object.</span>

<span class="sd">        Returns:</span>
<span class="sd">            A BandStructure object</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">labels_dict</span> <span class="o">=</span> <span class="n">d</span><span class="p">[</span><span class="s1">&#39;labels_dict&#39;</span><span class="p">]</span>
        <span class="n">projections</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="n">structure</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;bands&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">values</span><span class="p">())[</span><span class="mi">0</span><span class="p">],</span> <span class="nb">dict</span><span class="p">):</span>
            <span class="n">eigenvals</span> <span class="o">=</span> <span class="p">{</span><span class="n">Spin</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">k</span><span class="p">)):</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;bands&#39;</span><span class="p">][</span><span class="n">k</span><span class="p">][</span><span class="s1">&#39;data&#39;</span><span class="p">])</span>
                         <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s1">&#39;bands&#39;</span><span class="p">]}</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">eigenvals</span> <span class="o">=</span> <span class="p">{</span><span class="n">Spin</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">k</span><span class="p">)):</span> <span class="n">d</span><span class="p">[</span><span class="s1">&#39;bands&#39;</span><span class="p">][</span><span class="n">k</span><span class="p">]</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s1">&#39;bands&#39;</span><span class="p">]}</span>
        <span class="k">if</span> <span class="s1">&#39;structure&#39;</span> <span class="ow">in</span> <span class="n">d</span><span class="p">:</span>
            <span class="n">structure</span> <span class="o">=</span> <span class="n">Structure</span><span class="o">.</span><span class="n">from_dict</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;structure&#39;</span><span class="p">])</span>
        <span class="k">if</span> <span class="n">d</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;projections&#39;</span><span class="p">):</span>
            <span class="n">projections</span> <span class="o">=</span> <span class="p">{</span><span class="n">Spin</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">spin</span><span class="p">)):</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>
                           <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;projections&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>

        <span class="k">return</span> <span class="n">BandStructure</span><span class="p">(</span>
            <span class="n">d</span><span class="p">[</span><span class="s1">&#39;kpoints&#39;</span><span class="p">],</span> <span class="n">eigenvals</span><span class="p">,</span>
            <span class="n">Lattice</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;lattice_rec&#39;</span><span class="p">][</span><span class="s1">&#39;matrix&#39;</span><span class="p">]),</span> <span class="n">d</span><span class="p">[</span><span class="s1">&#39;efermi&#39;</span><span class="p">],</span>
            <span class="n">labels_dict</span><span class="p">,</span> <span class="n">structure</span><span class="o">=</span><span class="n">structure</span><span class="p">,</span> <span class="n">projections</span><span class="o">=</span><span class="n">projections</span><span class="p">)</span></div>

<div class="viewcode-block" id="BandStructure.from_old_dict"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.bandstructure.html#pymatgen.electronic_structure.bandstructure.BandStructure.from_old_dict">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_old_dict</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">d</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            d (dict): A dict with all data for a band structure symm line</span>
<span class="sd">                object.</span>
<span class="sd">        Returns:</span>
<span class="sd">            A BandStructureSymmLine object</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># Strip the label to recover initial string (see trick used in as_dict to handle $ chars)</span>
        <span class="n">labels_dict</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="o">.</span><span class="n">strip</span><span class="p">():</span> <span class="n">v</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s1">&#39;labels_dict&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
        <span class="n">projections</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="n">structure</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">if</span> <span class="s1">&#39;projections&#39;</span> <span class="ow">in</span> <span class="n">d</span> <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;projections&#39;</span><span class="p">])</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">structure</span> <span class="o">=</span> <span class="n">Structure</span><span class="o">.</span><span class="n">from_dict</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;structure&#39;</span><span class="p">])</span>
            <span class="n">projections</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="k">for</span> <span class="n">spin</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s1">&#39;projections&#39;</span><span class="p">]:</span>
                <span class="n">dd</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;projections&#39;</span><span class="p">][</span><span class="n">spin</span><span class="p">])):</span>
                    <span class="n">ddd</span> <span class="o">=</span> <span class="p">[]</span>
                    <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;projections&#39;</span><span class="p">][</span><span class="n">spin</span><span class="p">][</span><span class="n">i</span><span class="p">])):</span>
                        <span class="n">dddd</span> <span class="o">=</span> <span class="p">[]</span>
                        <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;projections&#39;</span><span class="p">][</span><span class="n">spin</span><span class="p">][</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">])):</span>
                            <span class="n">ddddd</span> <span class="o">=</span> <span class="p">[]</span>
                            <span class="n">orb</span> <span class="o">=</span> <span class="n">Orbital</span><span class="p">(</span><span class="n">k</span><span class="p">)</span><span class="o">.</span><span class="n">name</span>
                            <span class="k">for</span> <span class="n">l</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;projections&#39;</span><span class="p">][</span><span class="n">spin</span><span class="p">][</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span>
                                                   <span class="n">orb</span><span class="p">])):</span>
                                <span class="n">ddddd</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;projections&#39;</span><span class="p">][</span><span class="n">spin</span><span class="p">][</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span>
                                                 <span class="n">orb</span><span class="p">][</span><span class="n">l</span><span class="p">])</span>
                            <span class="n">dddd</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">ddddd</span><span class="p">))</span>
                        <span class="n">ddd</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">dddd</span><span class="p">))</span>
                    <span class="n">dd</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">ddd</span><span class="p">))</span>
                <span class="n">projections</span><span class="p">[</span><span class="n">Spin</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">spin</span><span class="p">))]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">dd</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">BandStructure</span><span class="p">(</span>
            <span class="n">d</span><span class="p">[</span><span class="s1">&#39;kpoints&#39;</span><span class="p">],</span> <span class="p">{</span><span class="n">Spin</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">k</span><span class="p">)):</span> <span class="n">d</span><span class="p">[</span><span class="s1">&#39;bands&#39;</span><span class="p">][</span><span class="n">k</span><span class="p">]</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s1">&#39;bands&#39;</span><span class="p">]},</span>
            <span class="n">Lattice</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;lattice_rec&#39;</span><span class="p">][</span><span class="s1">&#39;matrix&#39;</span><span class="p">]),</span> <span class="n">d</span><span class="p">[</span><span class="s1">&#39;efermi&#39;</span><span class="p">],</span>
            <span class="n">labels_dict</span><span class="p">,</span> <span class="n">structure</span><span class="o">=</span><span class="n">structure</span><span class="p">,</span> <span class="n">projections</span><span class="o">=</span><span class="n">projections</span><span class="p">)</span></div></div>


<div class="viewcode-block" id="BandStructureSymmLine"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.bandstructure.html#pymatgen.electronic_structure.bandstructure.BandStructureSymmLine">[docs]</a><span class="k">class</span> <span class="nc">BandStructureSymmLine</span><span class="p">(</span><span class="n">BandStructure</span><span class="p">,</span> <span class="n">MSONable</span><span class="p">):</span>
    <span class="sa">r</span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    This object stores band structures along selected (symmetry) lines in the</span>
<span class="sd">    Brillouin zone. We call the different symmetry lines (ex: \\Gamma to Z)</span>
<span class="sd">    &quot;branches&quot;.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">kpoints</span><span class="p">,</span> <span class="n">eigenvals</span><span class="p">,</span> <span class="n">lattice</span><span class="p">,</span> <span class="n">efermi</span><span class="p">,</span> <span class="n">labels_dict</span><span class="p">,</span>
                 <span class="n">coords_are_cartesian</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">structure</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">projections</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            kpoints: list of kpoint as numpy arrays, in frac_coords of the</span>
<span class="sd">                given lattice by default</span>
<span class="sd">            eigenvals: dict of energies for spin up and spin down</span>
<span class="sd">                {Spin.up:[][],Spin.down:[][]}, the first index of the array</span>
<span class="sd">                [][] refers to the band and the second to the index of the</span>
<span class="sd">                kpoint. The kpoints are ordered according to the order of the</span>
<span class="sd">                kpoints array. If the band structure is not spin polarized, we</span>
<span class="sd">                only store one data set under Spin.up.</span>
<span class="sd">            lattice: The reciprocal lattice.</span>
<span class="sd">                Pymatgen uses the physics convention of reciprocal lattice vectors</span>
<span class="sd">                WITH a 2*pi coefficient</span>
<span class="sd">            efermi: fermi energy</span>
<span class="sd">            label_dict: (dict) of {} this link a kpoint (in frac coords or</span>
<span class="sd">                cartesian coordinates depending on the coords).</span>
<span class="sd">            coords_are_cartesian: Whether coordinates are cartesian.</span>
<span class="sd">            structure: The crystal structure (as a pymatgen Structure object)</span>
<span class="sd">                associated with the band structure. This is needed if we</span>
<span class="sd">                provide projections to the band structure.</span>
<span class="sd">            projections: dict of orbital projections as {spin: ndarray}. The</span>
<span class="sd">                indices of the ndarrayare [band_index, kpoint_index, orbital_index,</span>
<span class="sd">                ion_index].If the band structure is not spin polarized, we only</span>
<span class="sd">                store one data set under Spin.up.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span>
            <span class="n">kpoints</span><span class="p">,</span> <span class="n">eigenvals</span><span class="p">,</span> <span class="n">lattice</span><span class="p">,</span> <span class="n">efermi</span><span class="p">,</span> <span class="n">labels_dict</span><span class="p">,</span>
            <span class="n">coords_are_cartesian</span><span class="p">,</span> <span class="n">structure</span><span class="p">,</span> <span class="n">projections</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">distance</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">branches</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">one_group</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">branches_tmp</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="c1"># get labels and distance for each kpoint</span>
        <span class="n">previous_kpoint</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">kpoints</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="n">previous_distance</span> <span class="o">=</span> <span class="mf">0.0</span>

        <span class="n">previous_label</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">kpoints</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">label</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">kpoints</span><span class="p">)):</span>
            <span class="n">label</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">kpoints</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">label</span>
            <span class="k">if</span> <span class="n">label</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">previous_label</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">distance</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">previous_distance</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">distance</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                    <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">kpoints</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">cart_coords</span> <span class="o">-</span>
                                   <span class="n">previous_kpoint</span><span class="o">.</span><span class="n">cart_coords</span><span class="p">)</span> <span class="o">+</span>
                    <span class="n">previous_distance</span><span class="p">)</span>
            <span class="n">previous_kpoint</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">kpoints</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
            <span class="n">previous_distance</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">distance</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
            <span class="k">if</span> <span class="n">label</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">previous_label</span><span class="p">:</span>
                    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">one_group</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span>
                        <span class="n">branches_tmp</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">one_group</span><span class="p">)</span>
                    <span class="n">one_group</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="n">previous_label</span> <span class="o">=</span> <span class="n">label</span>
            <span class="n">one_group</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>

        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">one_group</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">branches_tmp</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">one_group</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="n">branches_tmp</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">branches</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                <span class="p">{</span><span class="s2">&quot;start_index&quot;</span><span class="p">:</span> <span class="n">b</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="s2">&quot;end_index&quot;</span><span class="p">:</span> <span class="n">b</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">],</span>
                 <span class="s2">&quot;name&quot;</span><span class="p">:</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">kpoints</span><span class="p">[</span><span class="n">b</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span><span class="o">.</span><span class="n">label</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;-&quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">kpoints</span><span class="p">[</span><span class="n">b</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]]</span><span class="o">.</span><span class="n">label</span><span class="p">)})</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">is_spin_polarized</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">bands</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">is_spin_polarized</span> <span class="o">=</span> <span class="kc">True</span>

<div class="viewcode-block" id="BandStructureSymmLine.get_equivalent_kpoints"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.bandstructure.html#pymatgen.electronic_structure.bandstructure.BandStructureSymmLine.get_equivalent_kpoints">[docs]</a>    <span class="k">def</span> <span class="nf">get_equivalent_kpoints</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">index</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the list of kpoint indices equivalent (meaning they are the</span>
<span class="sd">        same frac coords) to the given one.</span>

<span class="sd">        Args:</span>
<span class="sd">            index: the kpoint index</span>

<span class="sd">        Returns:</span>
<span class="sd">            a list of equivalent indices</span>

<span class="sd">        TODO: now it uses the label we might want to use coordinates instead</span>
<span class="sd">        (in case there was a mislabel)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># if the kpoint has no label it can&quot;t have a repetition along the band</span>
        <span class="c1"># structure line object</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">kpoints</span><span class="p">[</span><span class="n">index</span><span class="p">]</span><span class="o">.</span><span class="n">label</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">return</span> <span class="p">[</span><span class="n">index</span><span class="p">]</span>

        <span class="n">list_index_kpoints</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">kpoints</span><span class="p">)):</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">kpoints</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">label</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">kpoints</span><span class="p">[</span><span class="n">index</span><span class="p">]</span><span class="o">.</span><span class="n">label</span><span class="p">:</span>
                <span class="n">list_index_kpoints</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">list_index_kpoints</span></div>

<div class="viewcode-block" id="BandStructureSymmLine.get_branch"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.bandstructure.html#pymatgen.electronic_structure.bandstructure.BandStructureSymmLine.get_branch">[docs]</a>    <span class="k">def</span> <span class="nf">get_branch</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">index</span><span class="p">):</span>
        <span class="sa">r</span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns in what branch(es) is the kpoint. There can be several</span>
<span class="sd">        branches.</span>

<span class="sd">        Args:</span>
<span class="sd">            index: the kpoint index</span>

<span class="sd">        Returns:</span>
<span class="sd">            A list of dictionaries [{&quot;name&quot;,&quot;start_index&quot;,&quot;end_index&quot;,&quot;index&quot;}]</span>
<span class="sd">            indicating all branches in which the k_point is. It takes into</span>
<span class="sd">            account the fact that one kpoint (e.g., \\Gamma) can be in several</span>
<span class="sd">            branches</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">to_return</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_equivalent_kpoints</span><span class="p">(</span><span class="n">index</span><span class="p">):</span>
            <span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">branches</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">b</span><span class="p">[</span><span class="s2">&quot;start_index&quot;</span><span class="p">]</span> <span class="o">&lt;=</span> <span class="n">i</span> <span class="o">&lt;=</span> <span class="n">b</span><span class="p">[</span><span class="s2">&quot;end_index&quot;</span><span class="p">]:</span>
                    <span class="n">to_return</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s2">&quot;name&quot;</span><span class="p">:</span> <span class="n">b</span><span class="p">[</span><span class="s2">&quot;name&quot;</span><span class="p">],</span>
                                      <span class="s2">&quot;start_index&quot;</span><span class="p">:</span> <span class="n">b</span><span class="p">[</span><span class="s2">&quot;start_index&quot;</span><span class="p">],</span>
                                      <span class="s2">&quot;end_index&quot;</span><span class="p">:</span> <span class="n">b</span><span class="p">[</span><span class="s2">&quot;end_index&quot;</span><span class="p">],</span>
                                      <span class="s2">&quot;index&quot;</span><span class="p">:</span> <span class="n">i</span><span class="p">})</span>
        <span class="k">return</span> <span class="n">to_return</span></div>

<div class="viewcode-block" id="BandStructureSymmLine.apply_scissor"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.bandstructure.html#pymatgen.electronic_structure.bandstructure.BandStructureSymmLine.apply_scissor">[docs]</a>    <span class="k">def</span> <span class="nf">apply_scissor</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">new_band_gap</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Apply a scissor operator (shift of the CBM) to fit the given band gap.</span>
<span class="sd">        If it&#39;s a metal. We look for the band crossing the fermi level</span>
<span class="sd">        and shift this one up. This will not work all the time for metals!</span>

<span class="sd">        Args:</span>
<span class="sd">            new_band_gap: the band gap the scissor band structure need to have.</span>

<span class="sd">        Returns:</span>
<span class="sd">            a BandStructureSymmLine object with the applied scissor shift</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_metal</span><span class="p">():</span>
            <span class="c1"># moves then the highest index band crossing the fermi level</span>
            <span class="c1"># find this band...</span>
            <span class="n">max_index</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1000</span>
            <span class="c1"># spin_index = None</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nb_bands</span><span class="p">):</span>
                <span class="n">below</span> <span class="o">=</span> <span class="kc">False</span>
                <span class="n">above</span> <span class="o">=</span> <span class="kc">False</span>
                <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">kpoints</span><span class="p">)):</span>
                    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">bands</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">][</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span><span class="p">:</span>
                        <span class="n">below</span> <span class="o">=</span> <span class="kc">True</span>
                    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">bands</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">][</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span><span class="p">:</span>
                        <span class="n">above</span> <span class="o">=</span> <span class="kc">True</span>
                <span class="k">if</span> <span class="n">above</span> <span class="ow">and</span> <span class="n">below</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">i</span> <span class="o">&gt;</span> <span class="n">max_index</span><span class="p">:</span>
                        <span class="n">max_index</span> <span class="o">=</span> <span class="n">i</span>
                        <span class="c1"># spin_index = Spin.up</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_spin_polarized</span><span class="p">:</span>
                    <span class="n">below</span> <span class="o">=</span> <span class="kc">False</span>
                    <span class="n">above</span> <span class="o">=</span> <span class="kc">False</span>
                    <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">kpoints</span><span class="p">)):</span>
                        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">bands</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">][</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span><span class="p">:</span>
                            <span class="n">below</span> <span class="o">=</span> <span class="kc">True</span>
                        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">bands</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">][</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span><span class="p">:</span>
                            <span class="n">above</span> <span class="o">=</span> <span class="kc">True</span>
                    <span class="k">if</span> <span class="n">above</span> <span class="ow">and</span> <span class="n">below</span><span class="p">:</span>
                        <span class="k">if</span> <span class="n">i</span> <span class="o">&gt;</span> <span class="n">max_index</span><span class="p">:</span>
                            <span class="n">max_index</span> <span class="o">=</span> <span class="n">i</span>
                            <span class="c1"># spin_index = Spin.down</span>
            <span class="n">old_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">as_dict</span><span class="p">()</span>
            <span class="n">shift</span> <span class="o">=</span> <span class="n">new_band_gap</span>
            <span class="k">for</span> <span class="n">spin</span> <span class="ow">in</span> <span class="n">old_dict</span><span class="p">[</span><span class="s1">&#39;bands&#39;</span><span class="p">]:</span>
                <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">old_dict</span><span class="p">[</span><span class="s1">&#39;bands&#39;</span><span class="p">][</span><span class="n">spin</span><span class="p">])):</span>
                    <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">old_dict</span><span class="p">[</span><span class="s1">&#39;bands&#39;</span><span class="p">][</span><span class="n">spin</span><span class="p">][</span><span class="n">k</span><span class="p">])):</span>
                        <span class="k">if</span> <span class="n">k</span> <span class="o">&gt;=</span> <span class="n">max_index</span><span class="p">:</span>
                            <span class="n">old_dict</span><span class="p">[</span><span class="s1">&#39;bands&#39;</span><span class="p">][</span><span class="n">spin</span><span class="p">][</span><span class="n">k</span><span class="p">][</span><span class="n">v</span><span class="p">]</span> <span class="o">=</span> \
                                <span class="n">old_dict</span><span class="p">[</span><span class="s1">&#39;bands&#39;</span><span class="p">][</span><span class="n">spin</span><span class="p">][</span><span class="n">k</span><span class="p">][</span><span class="n">v</span><span class="p">]</span> <span class="o">+</span> <span class="n">shift</span>
        <span class="k">else</span><span class="p">:</span>

            <span class="n">shift</span> <span class="o">=</span> <span class="n">new_band_gap</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_band_gap</span><span class="p">()[</span><span class="s1">&#39;energy&#39;</span><span class="p">]</span>
            <span class="n">old_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">as_dict</span><span class="p">()</span>
            <span class="k">for</span> <span class="n">spin</span> <span class="ow">in</span> <span class="n">old_dict</span><span class="p">[</span><span class="s1">&#39;bands&#39;</span><span class="p">]:</span>
                <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">old_dict</span><span class="p">[</span><span class="s1">&#39;bands&#39;</span><span class="p">][</span><span class="n">spin</span><span class="p">])):</span>
                    <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">old_dict</span><span class="p">[</span><span class="s1">&#39;bands&#39;</span><span class="p">][</span><span class="n">spin</span><span class="p">][</span><span class="n">k</span><span class="p">])):</span>
                        <span class="k">if</span> <span class="n">old_dict</span><span class="p">[</span><span class="s1">&#39;bands&#39;</span><span class="p">][</span><span class="n">spin</span><span class="p">][</span><span class="n">k</span><span class="p">][</span><span class="n">v</span><span class="p">]</span> <span class="o">&gt;=</span> \
                                <span class="n">old_dict</span><span class="p">[</span><span class="s1">&#39;cbm&#39;</span><span class="p">][</span><span class="s1">&#39;energy&#39;</span><span class="p">]:</span>
                            <span class="n">old_dict</span><span class="p">[</span><span class="s1">&#39;bands&#39;</span><span class="p">][</span><span class="n">spin</span><span class="p">][</span><span class="n">k</span><span class="p">][</span><span class="n">v</span><span class="p">]</span> <span class="o">=</span> \
                                <span class="n">old_dict</span><span class="p">[</span><span class="s1">&#39;bands&#39;</span><span class="p">][</span><span class="n">spin</span><span class="p">][</span><span class="n">k</span><span class="p">][</span><span class="n">v</span><span class="p">]</span> <span class="o">+</span> <span class="n">shift</span>
            <span class="n">old_dict</span><span class="p">[</span><span class="s1">&#39;efermi&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">old_dict</span><span class="p">[</span><span class="s1">&#39;efermi&#39;</span><span class="p">]</span> <span class="o">+</span> <span class="n">shift</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">from_dict</span><span class="p">(</span><span class="n">old_dict</span><span class="p">)</span></div>

<div class="viewcode-block" id="BandStructureSymmLine.as_dict"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.bandstructure.html#pymatgen.electronic_structure.bandstructure.BandStructureSymmLine.as_dict">[docs]</a>    <span class="k">def</span> <span class="nf">as_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Json-serializable dict representation of BandStructureSymmLine.</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="n">d</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;@module&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__module__</span><span class="p">,</span>
             <span class="s2">&quot;@class&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span>
             <span class="s2">&quot;lattice_rec&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">lattice_rec</span><span class="o">.</span><span class="n">as_dict</span><span class="p">(),</span> <span class="s2">&quot;efermi&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span><span class="p">,</span>
             <span class="s2">&quot;kpoints&quot;</span><span class="p">:</span> <span class="p">[]}</span>
        <span class="c1"># kpoints are not kpoint objects dicts but are frac coords (this makes</span>
        <span class="c1"># the dict smaller and avoids the repetition of the lattice</span>
        <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">kpoints</span><span class="p">:</span>
            <span class="n">d</span><span class="p">[</span><span class="s2">&quot;kpoints&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">k</span><span class="o">.</span><span class="n">as_dict</span><span class="p">()[</span><span class="s2">&quot;fcoords&quot;</span><span class="p">])</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;branches&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">branches</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;bands&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="nb">str</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">spin</span><span class="p">)):</span> <span class="bp">self</span><span class="o">.</span><span class="n">bands</span><span class="p">[</span><span class="n">spin</span><span class="p">]</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
                      <span class="k">for</span> <span class="n">spin</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bands</span><span class="p">}</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;is_metal&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_metal</span><span class="p">()</span>
        <span class="n">vbm</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_vbm</span><span class="p">()</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;vbm&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;energy&quot;</span><span class="p">:</span> <span class="n">vbm</span><span class="p">[</span><span class="s2">&quot;energy&quot;</span><span class="p">],</span>
                    <span class="s2">&quot;kpoint_index&quot;</span><span class="p">:</span> <span class="n">vbm</span><span class="p">[</span><span class="s2">&quot;kpoint_index&quot;</span><span class="p">],</span>
                    <span class="s2">&quot;band_index&quot;</span><span class="p">:</span> <span class="p">{</span><span class="nb">str</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">spin</span><span class="p">)):</span> <span class="n">vbm</span><span class="p">[</span><span class="s2">&quot;band_index&quot;</span><span class="p">][</span><span class="n">spin</span><span class="p">]</span>
                                   <span class="k">for</span> <span class="n">spin</span> <span class="ow">in</span> <span class="n">vbm</span><span class="p">[</span><span class="s2">&quot;band_index&quot;</span><span class="p">]},</span>
                    <span class="s1">&#39;projections&#39;</span><span class="p">:</span> <span class="p">{</span><span class="nb">str</span><span class="p">(</span><span class="n">spin</span><span class="p">):</span> <span class="n">v</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span> <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">vbm</span><span class="p">[</span>
                        <span class="s1">&#39;projections&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">()}}</span>
        <span class="n">cbm</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_cbm</span><span class="p">()</span>
        <span class="n">d</span><span class="p">[</span><span class="s1">&#39;cbm&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;energy&#39;</span><span class="p">:</span> <span class="n">cbm</span><span class="p">[</span><span class="s1">&#39;energy&#39;</span><span class="p">],</span>
                    <span class="s1">&#39;kpoint_index&#39;</span><span class="p">:</span> <span class="n">cbm</span><span class="p">[</span><span class="s1">&#39;kpoint_index&#39;</span><span class="p">],</span>
                    <span class="s1">&#39;band_index&#39;</span><span class="p">:</span> <span class="p">{</span><span class="nb">str</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">spin</span><span class="p">)):</span> <span class="n">cbm</span><span class="p">[</span><span class="s1">&#39;band_index&#39;</span><span class="p">][</span><span class="n">spin</span><span class="p">]</span>
                                   <span class="k">for</span> <span class="n">spin</span> <span class="ow">in</span> <span class="n">cbm</span><span class="p">[</span><span class="s1">&#39;band_index&#39;</span><span class="p">]},</span>
                    <span class="s1">&#39;projections&#39;</span><span class="p">:</span> <span class="p">{</span><span class="nb">str</span><span class="p">(</span><span class="n">spin</span><span class="p">):</span> <span class="n">v</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span> <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">cbm</span><span class="p">[</span>
                        <span class="s1">&#39;projections&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">()}}</span>
        <span class="n">d</span><span class="p">[</span><span class="s1">&#39;band_gap&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_band_gap</span><span class="p">()</span>
        <span class="n">d</span><span class="p">[</span><span class="s1">&#39;labels_dict&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="n">d</span><span class="p">[</span><span class="s1">&#39;is_spin_polarized&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_spin_polarized</span>
        <span class="c1"># MongoDB does not accept keys starting with $. Add a blanck space to fix the problem</span>
        <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">labels_dict</span><span class="p">:</span>
            <span class="n">mongo_key</span> <span class="o">=</span> <span class="n">c</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">c</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">&quot;$&quot;</span><span class="p">)</span> <span class="k">else</span> <span class="s2">&quot; &quot;</span> <span class="o">+</span> <span class="n">c</span>
            <span class="n">d</span><span class="p">[</span><span class="s1">&#39;labels_dict&#39;</span><span class="p">][</span><span class="n">mongo_key</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">labels_dict</span><span class="p">[</span><span class="n">c</span><span class="p">]</span><span class="o">.</span><span class="n">as_dict</span><span class="p">()[</span>
                <span class="s1">&#39;fcoords&#39;</span><span class="p">]</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">projections</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">d</span><span class="p">[</span><span class="s1">&#39;structure&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="o">.</span><span class="n">as_dict</span><span class="p">()</span>
            <span class="n">d</span><span class="p">[</span><span class="s1">&#39;projections&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="nb">str</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">spin</span><span class="p">)):</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">v</span><span class="p">)</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
                                <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">projections</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
        <span class="k">return</span> <span class="n">d</span></div>

<div class="viewcode-block" id="BandStructureSymmLine.from_dict"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.bandstructure.html#pymatgen.electronic_structure.bandstructure.BandStructureSymmLine.from_dict">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_dict</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">d</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            d (dict): A dict with all data for a band structure symm line</span>
<span class="sd">                object.</span>

<span class="sd">        Returns:</span>
<span class="sd">            A BandStructureSymmLine object</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="c1"># Strip the label to recover initial string (see trick used in as_dict to handle $ chars)</span>
            <span class="n">labels_dict</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="o">.</span><span class="n">strip</span><span class="p">():</span> <span class="n">v</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s1">&#39;labels_dict&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
            <span class="n">projections</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="n">structure</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="k">if</span> <span class="n">d</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;projections&#39;</span><span class="p">):</span>
                <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;projections&quot;</span><span class="p">][</span><span class="s1">&#39;1&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">],</span> <span class="nb">dict</span><span class="p">):</span>
                    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Old band structure dict format detected!&quot;</span><span class="p">)</span>
                <span class="n">structure</span> <span class="o">=</span> <span class="n">Structure</span><span class="o">.</span><span class="n">from_dict</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;structure&#39;</span><span class="p">])</span>
                <span class="n">projections</span> <span class="o">=</span> <span class="p">{</span><span class="n">Spin</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">spin</span><span class="p">)):</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>
                               <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;projections&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>

            <span class="k">return</span> <span class="n">BandStructureSymmLine</span><span class="p">(</span>
                <span class="n">d</span><span class="p">[</span><span class="s1">&#39;kpoints&#39;</span><span class="p">],</span> <span class="p">{</span><span class="n">Spin</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">k</span><span class="p">)):</span> <span class="n">d</span><span class="p">[</span><span class="s1">&#39;bands&#39;</span><span class="p">][</span><span class="n">k</span><span class="p">]</span>
                               <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s1">&#39;bands&#39;</span><span class="p">]},</span>
                <span class="n">Lattice</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;lattice_rec&#39;</span><span class="p">][</span><span class="s1">&#39;matrix&#39;</span><span class="p">]),</span> <span class="n">d</span><span class="p">[</span><span class="s1">&#39;efermi&#39;</span><span class="p">],</span>
                <span class="n">labels_dict</span><span class="p">,</span> <span class="n">structure</span><span class="o">=</span><span class="n">structure</span><span class="p">,</span> <span class="n">projections</span><span class="o">=</span><span class="n">projections</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">Exception</span><span class="p">:</span>
            <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="s2">&quot;Trying from_dict failed. Now we are trying the old &quot;</span>
                          <span class="s2">&quot;format. Please convert your BS dicts to the new &quot;</span>
                          <span class="s2">&quot;format. The old format will be retired in pymatgen &quot;</span>
                          <span class="s2">&quot;5.0.&quot;</span><span class="p">)</span>
            <span class="k">return</span> <span class="n">BandStructureSymmLine</span><span class="o">.</span><span class="n">from_old_dict</span><span class="p">(</span><span class="n">d</span><span class="p">)</span></div>

<div class="viewcode-block" id="BandStructureSymmLine.from_old_dict"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.bandstructure.html#pymatgen.electronic_structure.bandstructure.BandStructureSymmLine.from_old_dict">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_old_dict</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">d</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            d (dict): A dict with all data for a band structure symm line</span>
<span class="sd">                object.</span>
<span class="sd">        Returns:</span>
<span class="sd">            A BandStructureSymmLine object</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># Strip the label to recover initial string (see trick used in as_dict to handle $ chars)</span>
        <span class="n">labels_dict</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="o">.</span><span class="n">strip</span><span class="p">():</span> <span class="n">v</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s1">&#39;labels_dict&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
        <span class="n">projections</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="n">structure</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">if</span> <span class="s1">&#39;projections&#39;</span> <span class="ow">in</span> <span class="n">d</span> <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;projections&#39;</span><span class="p">])</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">structure</span> <span class="o">=</span> <span class="n">Structure</span><span class="o">.</span><span class="n">from_dict</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;structure&#39;</span><span class="p">])</span>
            <span class="n">projections</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="k">for</span> <span class="n">spin</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s1">&#39;projections&#39;</span><span class="p">]:</span>
                <span class="n">dd</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;projections&#39;</span><span class="p">][</span><span class="n">spin</span><span class="p">])):</span>
                    <span class="n">ddd</span> <span class="o">=</span> <span class="p">[]</span>
                    <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;projections&#39;</span><span class="p">][</span><span class="n">spin</span><span class="p">][</span><span class="n">i</span><span class="p">])):</span>
                        <span class="n">dddd</span> <span class="o">=</span> <span class="p">[]</span>
                        <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;projections&#39;</span><span class="p">][</span><span class="n">spin</span><span class="p">][</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">])):</span>
                            <span class="n">ddddd</span> <span class="o">=</span> <span class="p">[]</span>
                            <span class="n">orb</span> <span class="o">=</span> <span class="n">Orbital</span><span class="p">(</span><span class="n">k</span><span class="p">)</span><span class="o">.</span><span class="n">name</span>
                            <span class="k">for</span> <span class="n">l</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;projections&#39;</span><span class="p">][</span><span class="n">spin</span><span class="p">][</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span>
                                                   <span class="n">orb</span><span class="p">])):</span>
                                <span class="n">ddddd</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;projections&#39;</span><span class="p">][</span><span class="n">spin</span><span class="p">][</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span>
                                                 <span class="n">orb</span><span class="p">][</span><span class="n">l</span><span class="p">])</span>
                            <span class="n">dddd</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">ddddd</span><span class="p">))</span>
                        <span class="n">ddd</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">dddd</span><span class="p">))</span>
                    <span class="n">dd</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">ddd</span><span class="p">))</span>
                <span class="n">projections</span><span class="p">[</span><span class="n">Spin</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">spin</span><span class="p">))]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">dd</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">BandStructureSymmLine</span><span class="p">(</span>
            <span class="n">d</span><span class="p">[</span><span class="s1">&#39;kpoints&#39;</span><span class="p">],</span> <span class="p">{</span><span class="n">Spin</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">k</span><span class="p">)):</span> <span class="n">d</span><span class="p">[</span><span class="s1">&#39;bands&#39;</span><span class="p">][</span><span class="n">k</span><span class="p">]</span>
                           <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s1">&#39;bands&#39;</span><span class="p">]},</span>
            <span class="n">Lattice</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;lattice_rec&#39;</span><span class="p">][</span><span class="s1">&#39;matrix&#39;</span><span class="p">]),</span> <span class="n">d</span><span class="p">[</span><span class="s1">&#39;efermi&#39;</span><span class="p">],</span>
            <span class="n">labels_dict</span><span class="p">,</span> <span class="n">structure</span><span class="o">=</span><span class="n">structure</span><span class="p">,</span> <span class="n">projections</span><span class="o">=</span><span class="n">projections</span><span class="p">)</span></div></div>


<div class="viewcode-block" id="LobsterBandStructureSymmLine"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.bandstructure.html#pymatgen.electronic_structure.bandstructure.LobsterBandStructureSymmLine">[docs]</a><span class="k">class</span> <span class="nc">LobsterBandStructureSymmLine</span><span class="p">(</span><span class="n">BandStructureSymmLine</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Lobster subclass of BandStructure with customized functions.</span>
<span class="sd">    &quot;&quot;&quot;</span>

<div class="viewcode-block" id="LobsterBandStructureSymmLine.as_dict"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.bandstructure.html#pymatgen.electronic_structure.bandstructure.LobsterBandStructureSymmLine.as_dict">[docs]</a>    <span class="k">def</span> <span class="nf">as_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Json-serializable dict representation of BandStructureSymmLine.</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="n">d</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;@module&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__module__</span><span class="p">,</span>
             <span class="s2">&quot;@class&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span>
             <span class="s2">&quot;lattice_rec&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">lattice_rec</span><span class="o">.</span><span class="n">as_dict</span><span class="p">(),</span> <span class="s2">&quot;efermi&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span><span class="p">,</span>
             <span class="s2">&quot;kpoints&quot;</span><span class="p">:</span> <span class="p">[]}</span>
        <span class="c1"># kpoints are not kpoint objects dicts but are frac coords (this makes</span>
        <span class="c1"># the dict smaller and avoids the repetition of the lattice</span>
        <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">kpoints</span><span class="p">:</span>
            <span class="n">d</span><span class="p">[</span><span class="s2">&quot;kpoints&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">k</span><span class="o">.</span><span class="n">as_dict</span><span class="p">()[</span><span class="s2">&quot;fcoords&quot;</span><span class="p">])</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;branches&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">branches</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;bands&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="nb">str</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">spin</span><span class="p">)):</span> <span class="bp">self</span><span class="o">.</span><span class="n">bands</span><span class="p">[</span><span class="n">spin</span><span class="p">]</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
                      <span class="k">for</span> <span class="n">spin</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bands</span><span class="p">}</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;is_metal&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_metal</span><span class="p">()</span>
        <span class="n">vbm</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_vbm</span><span class="p">()</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;vbm&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;energy&quot;</span><span class="p">:</span> <span class="n">vbm</span><span class="p">[</span><span class="s2">&quot;energy&quot;</span><span class="p">],</span>
                    <span class="s2">&quot;kpoint_index&quot;</span><span class="p">:</span> <span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">vbm</span><span class="p">[</span><span class="s2">&quot;kpoint_index&quot;</span><span class="p">]],</span>
                    <span class="s2">&quot;band_index&quot;</span><span class="p">:</span> <span class="p">{</span><span class="nb">str</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">spin</span><span class="p">)):</span> <span class="n">vbm</span><span class="p">[</span><span class="s2">&quot;band_index&quot;</span><span class="p">][</span><span class="n">spin</span><span class="p">]</span>
                                   <span class="k">for</span> <span class="n">spin</span> <span class="ow">in</span> <span class="n">vbm</span><span class="p">[</span><span class="s2">&quot;band_index&quot;</span><span class="p">]},</span>
                    <span class="s1">&#39;projections&#39;</span><span class="p">:</span> <span class="p">{</span><span class="nb">str</span><span class="p">(</span><span class="n">spin</span><span class="p">):</span> <span class="n">v</span> <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">vbm</span><span class="p">[</span>
                        <span class="s1">&#39;projections&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">()}}</span>
        <span class="n">cbm</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_cbm</span><span class="p">()</span>
        <span class="n">d</span><span class="p">[</span><span class="s1">&#39;cbm&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;energy&#39;</span><span class="p">:</span> <span class="n">cbm</span><span class="p">[</span><span class="s1">&#39;energy&#39;</span><span class="p">],</span>
                    <span class="s1">&#39;kpoint_index&#39;</span><span class="p">:</span> <span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">cbm</span><span class="p">[</span><span class="s2">&quot;kpoint_index&quot;</span><span class="p">]],</span>
                    <span class="s1">&#39;band_index&#39;</span><span class="p">:</span> <span class="p">{</span><span class="nb">str</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">spin</span><span class="p">)):</span> <span class="n">cbm</span><span class="p">[</span><span class="s1">&#39;band_index&#39;</span><span class="p">][</span><span class="n">spin</span><span class="p">]</span>
                                   <span class="k">for</span> <span class="n">spin</span> <span class="ow">in</span> <span class="n">cbm</span><span class="p">[</span><span class="s1">&#39;band_index&#39;</span><span class="p">]},</span>
                    <span class="s1">&#39;projections&#39;</span><span class="p">:</span> <span class="p">{</span><span class="nb">str</span><span class="p">(</span><span class="n">spin</span><span class="p">):</span> <span class="n">v</span> <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">cbm</span><span class="p">[</span>
                        <span class="s1">&#39;projections&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">()}}</span>
        <span class="n">d</span><span class="p">[</span><span class="s1">&#39;band_gap&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_band_gap</span><span class="p">()</span>
        <span class="n">d</span><span class="p">[</span><span class="s1">&#39;labels_dict&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="n">d</span><span class="p">[</span><span class="s1">&#39;is_spin_polarized&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_spin_polarized</span>
        <span class="c1"># MongoDB does not accept keys starting with $. Add a blanck space to fix the problem</span>
        <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">labels_dict</span><span class="p">:</span>
            <span class="n">mongo_key</span> <span class="o">=</span> <span class="n">c</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">c</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">&quot;$&quot;</span><span class="p">)</span> <span class="k">else</span> <span class="s2">&quot; &quot;</span> <span class="o">+</span> <span class="n">c</span>
            <span class="n">d</span><span class="p">[</span><span class="s1">&#39;labels_dict&#39;</span><span class="p">][</span><span class="n">mongo_key</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">labels_dict</span><span class="p">[</span><span class="n">c</span><span class="p">]</span><span class="o">.</span><span class="n">as_dict</span><span class="p">()[</span>
                <span class="s1">&#39;fcoords&#39;</span><span class="p">]</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">projections</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">d</span><span class="p">[</span><span class="s1">&#39;structure&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="o">.</span><span class="n">as_dict</span><span class="p">()</span>
            <span class="n">d</span><span class="p">[</span><span class="s1">&#39;projections&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="nb">str</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">spin</span><span class="p">)):</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">v</span><span class="p">)</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
                                <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">projections</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
        <span class="k">return</span> <span class="n">d</span></div>

<div class="viewcode-block" id="LobsterBandStructureSymmLine.from_dict"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.bandstructure.html#pymatgen.electronic_structure.bandstructure.LobsterBandStructureSymmLine.from_dict">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_dict</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">d</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            d (dict): A dict with all data for a band structure symm line</span>
<span class="sd">                object.</span>

<span class="sd">        Returns:</span>
<span class="sd">            A BandStructureSymmLine object</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="c1"># Strip the label to recover initial string (see trick used in as_dict to handle $ chars)</span>
            <span class="n">labels_dict</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="o">.</span><span class="n">strip</span><span class="p">():</span> <span class="n">v</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s1">&#39;labels_dict&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
            <span class="n">projections</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="n">structure</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="k">if</span> <span class="n">d</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;projections&#39;</span><span class="p">):</span>
                <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;projections&quot;</span><span class="p">][</span><span class="s1">&#39;1&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">],</span> <span class="nb">dict</span><span class="p">):</span>
                    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Old band structure dict format detected!&quot;</span><span class="p">)</span>
                <span class="n">structure</span> <span class="o">=</span> <span class="n">Structure</span><span class="o">.</span><span class="n">from_dict</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;structure&#39;</span><span class="p">])</span>
                <span class="n">projections</span> <span class="o">=</span> <span class="p">{</span><span class="n">Spin</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">spin</span><span class="p">)):</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>
                               <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;projections&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>

            <span class="k">return</span> <span class="n">LobsterBandStructureSymmLine</span><span class="p">(</span>
                <span class="n">d</span><span class="p">[</span><span class="s1">&#39;kpoints&#39;</span><span class="p">],</span> <span class="p">{</span><span class="n">Spin</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">k</span><span class="p">)):</span> <span class="n">d</span><span class="p">[</span><span class="s1">&#39;bands&#39;</span><span class="p">][</span><span class="n">k</span><span class="p">]</span>
                               <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s1">&#39;bands&#39;</span><span class="p">]},</span>
                <span class="n">Lattice</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;lattice_rec&#39;</span><span class="p">][</span><span class="s1">&#39;matrix&#39;</span><span class="p">]),</span> <span class="n">d</span><span class="p">[</span><span class="s1">&#39;efermi&#39;</span><span class="p">],</span>
                <span class="n">labels_dict</span><span class="p">,</span> <span class="n">structure</span><span class="o">=</span><span class="n">structure</span><span class="p">,</span> <span class="n">projections</span><span class="o">=</span><span class="n">projections</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">Exception</span><span class="p">:</span>
            <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="s2">&quot;Trying from_dict failed. Now we are trying the old &quot;</span>
                          <span class="s2">&quot;format. Please convert your BS dicts to the new &quot;</span>
                          <span class="s2">&quot;format. The old format will be retired in pymatgen &quot;</span>
                          <span class="s2">&quot;5.0.&quot;</span><span class="p">)</span>
            <span class="k">return</span> <span class="n">LobsterBandStructureSymmLine</span><span class="o">.</span><span class="n">from_old_dict</span><span class="p">(</span><span class="n">d</span><span class="p">)</span></div>

<div class="viewcode-block" id="LobsterBandStructureSymmLine.from_old_dict"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.bandstructure.html#pymatgen.electronic_structure.bandstructure.LobsterBandStructureSymmLine.from_old_dict">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_old_dict</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">d</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            d (dict): A dict with all data for a band structure symm line</span>
<span class="sd">                object.</span>
<span class="sd">        Returns:</span>
<span class="sd">            A BandStructureSymmLine object</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># Strip the label to recover initial string (see trick used in as_dict to handle $ chars)</span>
        <span class="n">labels_dict</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="o">.</span><span class="n">strip</span><span class="p">():</span> <span class="n">v</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s1">&#39;labels_dict&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
        <span class="n">projections</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="n">structure</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">if</span> <span class="s1">&#39;projections&#39;</span> <span class="ow">in</span> <span class="n">d</span> <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;projections&#39;</span><span class="p">])</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">structure</span> <span class="o">=</span> <span class="n">Structure</span><span class="o">.</span><span class="n">from_dict</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;structure&#39;</span><span class="p">])</span>
            <span class="n">projections</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="k">for</span> <span class="n">spin</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s1">&#39;projections&#39;</span><span class="p">]:</span>
                <span class="n">dd</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;projections&#39;</span><span class="p">][</span><span class="n">spin</span><span class="p">])):</span>
                    <span class="n">ddd</span> <span class="o">=</span> <span class="p">[]</span>
                    <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;projections&#39;</span><span class="p">][</span><span class="n">spin</span><span class="p">][</span><span class="n">i</span><span class="p">])):</span>
                        <span class="n">ddd</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;projections&#39;</span><span class="p">][</span><span class="n">spin</span><span class="p">][</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">])</span>
                    <span class="n">dd</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">ddd</span><span class="p">))</span>
                <span class="n">projections</span><span class="p">[</span><span class="n">Spin</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">spin</span><span class="p">))]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">dd</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">LobsterBandStructureSymmLine</span><span class="p">(</span>
            <span class="n">d</span><span class="p">[</span><span class="s1">&#39;kpoints&#39;</span><span class="p">],</span> <span class="p">{</span><span class="n">Spin</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">k</span><span class="p">)):</span> <span class="n">d</span><span class="p">[</span><span class="s1">&#39;bands&#39;</span><span class="p">][</span><span class="n">k</span><span class="p">]</span>
                           <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s1">&#39;bands&#39;</span><span class="p">]},</span>
            <span class="n">Lattice</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;lattice_rec&#39;</span><span class="p">][</span><span class="s1">&#39;matrix&#39;</span><span class="p">]),</span> <span class="n">d</span><span class="p">[</span><span class="s1">&#39;efermi&#39;</span><span class="p">],</span>
            <span class="n">labels_dict</span><span class="p">,</span> <span class="n">structure</span><span class="o">=</span><span class="n">structure</span><span class="p">,</span> <span class="n">projections</span><span class="o">=</span><span class="n">projections</span><span class="p">)</span></div>

<div class="viewcode-block" id="LobsterBandStructureSymmLine.get_projection_on_elements"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.bandstructure.html#pymatgen.electronic_structure.bandstructure.LobsterBandStructureSymmLine.get_projection_on_elements">[docs]</a>    <span class="k">def</span> <span class="nf">get_projection_on_elements</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Method returning a dictionary of projections on elements.</span>
<span class="sd">        It sums over all available orbitals for each element.</span>

<span class="sd">        Returns:</span>
<span class="sd">            a dictionary in the {Spin.up:[][{Element:values}],</span>
<span class="sd">            Spin.down:[][{Element:values}]} format</span>
<span class="sd">            if there is no projections in the band structure</span>
<span class="sd">            returns an empty dict</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">result</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">projections</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="n">result</span><span class="p">[</span><span class="n">spin</span><span class="p">]</span> <span class="o">=</span> <span class="p">[[</span><span class="n">collections</span><span class="o">.</span><span class="n">defaultdict</span><span class="p">(</span><span class="nb">float</span><span class="p">)</span>
                             <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">kpoints</span><span class="p">))]</span>
                            <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nb_bands</span><span class="p">)]</span>
            <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">j</span> <span class="ow">in</span> <span class="n">itertools</span><span class="o">.</span><span class="n">product</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nb_bands</span><span class="p">),</span>
                                          <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">kpoints</span><span class="p">))):</span>
                <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">v</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                    <span class="k">for</span> <span class="n">key2</span><span class="p">,</span> <span class="n">item2</span> <span class="ow">in</span> <span class="n">item</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                        <span class="n">specie</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">Element</span><span class="p">(</span><span class="n">re</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;[0-9]+&quot;</span><span class="p">,</span> <span class="n">key</span><span class="p">)[</span><span class="mi">0</span><span class="p">]))</span>
                        <span class="n">result</span><span class="p">[</span><span class="n">spin</span><span class="p">][</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">specie</span><span class="p">]</span> <span class="o">+=</span> <span class="n">item2</span>
        <span class="k">return</span> <span class="n">result</span></div>

<div class="viewcode-block" id="LobsterBandStructureSymmLine.get_projections_on_elements_and_orbitals"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.bandstructure.html#pymatgen.electronic_structure.bandstructure.LobsterBandStructureSymmLine.get_projections_on_elements_and_orbitals">[docs]</a>    <span class="k">def</span> <span class="nf">get_projections_on_elements_and_orbitals</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">el_orb_spec</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Method returning a dictionary of projections on elements and specific</span>
<span class="sd">        orbitals</span>

<span class="sd">        Args:</span>
<span class="sd">            el_orb_spec: A dictionary of Elements and Orbitals for which we want</span>
<span class="sd">                to have projections on. It is given as: {Element:[orbitals]},</span>
<span class="sd">                e.g., {&#39;Si&#39;:[&#39;3s&#39;,&#39;3p&#39;]} or {&#39;Si&#39;:[&#39;3s&#39;,&#39;3p_x&#39;, &#39;3p_y&#39;, &#39;3p_z&#39;]} depending on input files</span>

<span class="sd">        Returns:</span>
<span class="sd">            A dictionary of projections on elements in the</span>
<span class="sd">            {Spin.up:[][{Element:{orb:values}}],</span>
<span class="sd">            Spin.down:[][{Element:{orb:values}}]} format</span>
<span class="sd">            if there is no projections in the band structure returns an empty</span>
<span class="sd">            dict.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">result</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="n">el_orb_spec</span> <span class="o">=</span> <span class="p">{</span><span class="n">get_el_sp</span><span class="p">(</span><span class="n">el</span><span class="p">):</span> <span class="n">orbs</span> <span class="k">for</span> <span class="n">el</span><span class="p">,</span> <span class="n">orbs</span> <span class="ow">in</span> <span class="n">el_orb_spec</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
        <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">projections</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="n">result</span><span class="p">[</span><span class="n">spin</span><span class="p">]</span> <span class="o">=</span> <span class="p">[[{</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">):</span> <span class="n">collections</span><span class="o">.</span><span class="n">defaultdict</span><span class="p">(</span><span class="nb">float</span><span class="p">)</span>
                              <span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="n">el_orb_spec</span><span class="p">}</span>
                             <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">kpoints</span><span class="p">))]</span>
                            <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nb_bands</span><span class="p">)]</span>

            <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">j</span> <span class="ow">in</span> <span class="n">itertools</span><span class="o">.</span><span class="n">product</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nb_bands</span><span class="p">),</span>
                                          <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">kpoints</span><span class="p">))):</span>
                <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">v</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                    <span class="k">for</span> <span class="n">key2</span><span class="p">,</span> <span class="n">item2</span> <span class="ow">in</span> <span class="n">item</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                        <span class="n">specie</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">Element</span><span class="p">(</span><span class="n">re</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;[0-9]+&quot;</span><span class="p">,</span> <span class="n">key</span><span class="p">)[</span><span class="mi">0</span><span class="p">]))</span>
                        <span class="k">if</span> <span class="n">get_el_sp</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">specie</span><span class="p">))</span> <span class="ow">in</span> <span class="n">el_orb_spec</span><span class="p">:</span>
                            <span class="k">if</span> <span class="n">key2</span> <span class="ow">in</span> <span class="n">el_orb_spec</span><span class="p">[</span><span class="n">get_el_sp</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">specie</span><span class="p">))]:</span>
                                <span class="n">result</span><span class="p">[</span><span class="n">spin</span><span class="p">][</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">specie</span><span class="p">][</span><span class="n">key2</span><span class="p">]</span> <span class="o">+=</span> <span class="n">item2</span>
        <span class="k">return</span> <span class="n">result</span></div></div>


<div class="viewcode-block" id="get_reconstructed_band_structure"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.bandstructure.html#pymatgen.electronic_structure.bandstructure.get_reconstructed_band_structure">[docs]</a><span class="k">def</span> <span class="nf">get_reconstructed_band_structure</span><span class="p">(</span><span class="n">list_bs</span><span class="p">,</span> <span class="n">efermi</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    This method takes a list of band structures and reconstructs</span>
<span class="sd">    one band structure object from all of them.</span>

<span class="sd">    This is typically very useful when you split non self consistent</span>
<span class="sd">    band structure runs in several independent jobs and want to merge back</span>
<span class="sd">    the results</span>

<span class="sd">    Args:</span>
<span class="sd">        list_bs: A list of BandStructure or BandStructureSymmLine objects.</span>
<span class="sd">        efermi: The Fermi energy of the reconstructed band structure. If</span>
<span class="sd">            None is assigned an average of all the Fermi energy in each</span>
<span class="sd">            object in the list_bs is used.</span>

<span class="sd">    Returns:</span>
<span class="sd">        A BandStructure or BandStructureSymmLine object (depending on</span>
<span class="sd">        the type of the list_bs objects)</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="n">efermi</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
        <span class="n">efermi</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">([</span><span class="n">b</span><span class="o">.</span><span class="n">efermi</span> <span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="n">list_bs</span><span class="p">])</span> <span class="o">/</span> <span class="nb">len</span><span class="p">(</span><span class="n">list_bs</span><span class="p">)</span>

    <span class="n">kpoints</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="n">labels_dict</span> <span class="o">=</span> <span class="p">{}</span>
    <span class="n">rec_lattice</span> <span class="o">=</span> <span class="n">list_bs</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">lattice_rec</span>
    <span class="n">nb_bands</span> <span class="o">=</span> <span class="nb">min</span><span class="p">([</span><span class="n">list_bs</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">nb_bands</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">list_bs</span><span class="p">))])</span>

    <span class="n">kpoints</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">concatenate</span><span class="p">([[</span><span class="n">k</span><span class="o">.</span><span class="n">frac_coords</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">bs</span><span class="o">.</span><span class="n">kpoints</span><span class="p">]</span>
                              <span class="k">for</span> <span class="n">bs</span> <span class="ow">in</span> <span class="n">list_bs</span><span class="p">])</span>
    <span class="n">dicts</span> <span class="o">=</span> <span class="p">[</span><span class="n">bs</span><span class="o">.</span><span class="n">labels_dict</span> <span class="k">for</span> <span class="n">bs</span> <span class="ow">in</span> <span class="n">list_bs</span><span class="p">]</span>
    <span class="n">labels_dict</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">v</span><span class="o">.</span><span class="n">frac_coords</span> <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">dicts</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">d</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>

    <span class="n">eigenvals</span> <span class="o">=</span> <span class="p">{}</span>
    <span class="n">eigenvals</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">concatenate</span><span class="p">([</span><span class="n">bs</span><span class="o">.</span><span class="n">bands</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">][:</span><span class="n">nb_bands</span><span class="p">]</span>
                                         <span class="k">for</span> <span class="n">bs</span> <span class="ow">in</span> <span class="n">list_bs</span><span class="p">],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">list_bs</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">is_spin_polarized</span><span class="p">:</span>
        <span class="n">eigenvals</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">concatenate</span><span class="p">([</span><span class="n">bs</span><span class="o">.</span><span class="n">bands</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">][:</span><span class="n">nb_bands</span><span class="p">]</span>
                                               <span class="k">for</span> <span class="n">bs</span> <span class="ow">in</span> <span class="n">list_bs</span><span class="p">],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>

    <span class="n">projections</span> <span class="o">=</span> <span class="p">{}</span>
    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">list_bs</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">projections</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span>
        <span class="n">projs</span> <span class="o">=</span> <span class="p">[</span><span class="n">bs</span><span class="o">.</span><span class="n">projections</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">][:</span><span class="n">nb_bands</span><span class="p">]</span> <span class="k">for</span> <span class="n">bs</span> <span class="ow">in</span> <span class="n">list_bs</span><span class="p">]</span>
        <span class="n">projections</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">concatenate</span><span class="p">(</span><span class="n">projs</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">list_bs</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">is_spin_polarized</span><span class="p">:</span>
            <span class="n">projs</span> <span class="o">=</span> <span class="p">[</span><span class="n">bs</span><span class="o">.</span><span class="n">projections</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">][:</span><span class="n">nb_bands</span><span class="p">]</span> <span class="k">for</span> <span class="n">bs</span> <span class="ow">in</span> <span class="n">list_bs</span><span class="p">]</span>
            <span class="n">projections</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">concatenate</span><span class="p">(</span><span class="n">projs</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>

    <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">list_bs</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">BandStructureSymmLine</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">BandStructureSymmLine</span><span class="p">(</span><span class="n">kpoints</span><span class="p">,</span> <span class="n">eigenvals</span><span class="p">,</span> <span class="n">rec_lattice</span><span class="p">,</span>
                                     <span class="n">efermi</span><span class="p">,</span> <span class="n">labels_dict</span><span class="p">,</span>
                                     <span class="n">structure</span><span class="o">=</span><span class="n">list_bs</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">structure</span><span class="p">,</span>
                                     <span class="n">projections</span><span class="o">=</span><span class="n">projections</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="k">return</span> <span class="n">BandStructure</span><span class="p">(</span><span class="n">kpoints</span><span class="p">,</span> <span class="n">eigenvals</span><span class="p">,</span> <span class="n">rec_lattice</span><span class="p">,</span> <span class="n">efermi</span><span class="p">,</span>
                             <span class="n">labels_dict</span><span class="p">,</span> <span class="n">structure</span><span class="o">=</span><span class="n">list_bs</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">structure</span><span class="p">,</span>
                             <span class="n">projections</span><span class="o">=</span><span class="n">projections</span><span class="p">)</span></div>
</pre></div>

            <div class="clearer"></div>
          </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../pymatgen.html" >pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.electronic_structure.bandstructure</a></li> 
      </ul>
    </div>

    <div class="footer" role="contentinfo">
        &#169; Copyright 2011, Pymatgen Development Team.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
    </div>
<div class="footer">This page uses <a href="http://analytics.google.com/">
Google Analytics</a> to collect statistics. You can disable it by blocking
the JavaScript coming from www.google-analytics.com.
<script type="text/javascript">
  (function() {
    var ga = document.createElement('script');
    ga.src = ('https:' == document.location.protocol ?
              'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    ga.setAttribute('async', 'true');
    document.documentElement.firstChild.appendChild(ga);
  })();
</script>
</div>

  </body>
</html>